TreeView: OnSelectedNodeChanged not firing??

D

Dotnet Gruven

With this TreeView declaration:

<asp:TreeView ID="Cloner" runat="server"

SelectedNodeStyle-Font-Bold="true" SelectedNodeStyle-ForeColor="#003E21"

OnTreeNodePopulate="PopulateNode" OnSelectedNodeChanged="SelectNode"

ExpandDepth="0">

</asp:TreeView>

Nodes are added in PopulateNode() like so:

protected void PopulateNode(Object source, TreeNodeEventArgs e)

{

TreeNode newNode = null;

switch (e.Node.Depth)

{

case 0:

string locationIdStr = e.Node.Value;

try

{

int locationId = Convert.ToInt32(locationIdStr);

e2006TableAdapters.MenusTableAdapter mta = new e2006TableAdapters.MenusTableAdapter();

mta.FillByLocationId(myDto.Menus, locationId);

foreach (e2006Table.MenusRow menuRow in myDto.Menus)

{

newNode = new TreeNode(menuRow.MenuName, menuRow.MenuId.ToString());

newNode.SelectAction = TreeNodeSelectAction.Expand;

newNode.PopulateOnDemand = true;

e.Node.ChildNodes.Add(newNode);

}

}

catch { }

break;

// etc

And, finally, the leaf nodes are added with this code:

foreach (e2006.MenuItemsRow menuItems in myDto.MenuItems)

{

newNode = new TreeNode(menuItems.Name, menuItems.MenuItemId.ToString());

newNode.SelectAction = TreeNodeSelectAction.Select;

newNode.NavigateUrl = "";

e.Node.ChildNodes.Add(newNode);

}

The question is: WHY doesn't the OnSelectedNodeChanged="SelectNode"

protected void SelectNode(Object source, EventArgs e)

{ // This never fires!!!???!!!



TIA,

geo
 
K

Kevin Yu [MSFT]

Hi geo,

We have reviewed this issue and are currently researching on it. We will
update you ASAP. Thanks for your patience!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
S

Steven Cheng[MSFT]

Hi Geo,

Sorry for keep you waiting. As for the dynamically added TreeNode's
Selected event not fire problem, based on my research , it is due to the
TreeNode.SelectAction you set in the original code...

In order to make the "TreeNodePopulated" and "SelectedNodeChanged" event
get fired for your new created nodes, we should set their SelectAction to
"SelectExpand", e.g:

================================

protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs
e)
{
string name = e.Node.Text;
TreeNode node = null;
if (e.Node.ChildNodes == null || e.Node.ChildNodes.Count == 0)
{
for (int i = 0; i < 5; i++)
{
node = new TreeNode(name + i, name + i);
node.SelectAction = TreeNodeSelectAction.SelectExpand;
node.PopulateOnDemand = true;

e.Node.ChildNodes.Add(node);
}
}
}
=====================================

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Dotnet Gruven" <[email protected]>
| References: <[email protected]>
<kVbC#[email protected]>
| Subject: Re: TreeView: OnSelectedNodeChanged not firing??
| Date: Wed, 21 Dec 2005 09:03:24 -0500
| Lines: 19
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: c-24-128-25-74.hsd1.ma.comcast.net 24.128.25.74
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:366235
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Kevin, Is this issue still open?
|
| Thanks
| geo
|
| | > Hi geo,
| >
| > We have reviewed this issue and are currently researching on it. We will
| > update you ASAP. Thanks for your patience!
| >
| > Kevin Yu
| > =======
| > "This posting is provided "AS IS" with no warranties, and confers no
| > rights."
| >
|
|
|
 
E

Edward Kwan

Dear Sir,

I would like to check if the dynamically load nodes can still fire the

onselectednodechanged. Even if I changed to SelectExpand, it still does
not work. My code

is as follows. Please help. Thanks.



best regards,

Edward



<ASP:TreeView id="TreeView1" OnTreeNodePopulate="TreeNodePopulate"

OnSelectedNodeChanged="TreeNodeSelectedNodeChanged" ExpandDepth="0"
EnableViewState="false"

Visible=False ShowLines="true" runat="server"></ASP:TreeView>

Sub TreeNodeSelectedNodeChanged(ByVal sender As Object, ByVal e
As EventArgs)
Value = TreeView1.SelectedNode.Value
Text = TreeView1.SelectedNode.Text
TreeView1.Visible = False
End Sub
Sub TreeNodePopulate(ByVal sender As Object, ByVal e As
TreeNodeEventArgs)
SetDV()
Dim nodes As DataView = GetChilds(DV, e.Node.Value)
' Populate Treeview.
For Each row As DataRowView In nodes
Dim newNode As New TreeNode()
newNode.Text = row("description").ToString()
newNode.Value = row("code").ToString()
'If Not IsNumeric(newNode.Value) Then
newNode.SelectAction = TreeNodeSelectAction.SelectExpand
newNode.PopulateOnDemand = True
'End If
e.Node.ChildNodes.Add(newNode)
'AddChild(DV, headNode)
Next
End Sub
 
E

Edward Kwan

Dear Sir,

I would like to check if the dynamically load nodes can still fire the

onselectednodechanged. Even if I changed to SelectExpand, it still does
not work. My code

is as follows. Please help. Thanks.



best regards,

Edward



<ASP:TreeView id="TreeView1" OnTreeNodePopulate="TreeNodePopulate"

OnSelectedNodeChanged="TreeNodeSelectedNodeChanged" ExpandDepth="0"
EnableViewState="false"

Visible=False ShowLines="true" runat="server"></ASP:TreeView>

Sub TreeNodeSelectedNodeChanged(ByVal sender As Object, ByVal e
As EventArgs)
Value = TreeView1.SelectedNode.Value
Text = TreeView1.SelectedNode.Text
TreeView1.Visible = False
End Sub
Sub TreeNodePopulate(ByVal sender As Object, ByVal e As
TreeNodeEventArgs)
SetDV()
Dim nodes As DataView = GetChilds(DV, e.Node.Value)
' Populate Treeview.
For Each row As DataRowView In nodes
Dim newNode As New TreeNode()
newNode.Text = row("description").ToString()
newNode.Value = row("code").ToString()
'If Not IsNumeric(newNode.Value) Then
newNode.SelectAction = TreeNodeSelectAction.SelectExpand
newNode.PopulateOnDemand = True
'End If
e.Node.ChildNodes.Add(newNode)
'AddChild(DV, headNode)
Next
End Sub
 
Joined
Sep 8, 2008
Messages
1
Reaction score
0
Has this been fixed

I am also having this problem, and I have tried setting the Select action to SelectExpand. I need to find a way to programatically trigger the click event for a tree node, please help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top