TreeView: OnSelectedNodeChanged not firing??

  • Thread starter Thread starter Dotnet Gruven
  • Start date Start date
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
 
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."
 
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."
| >
|
|
|
 
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
 
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
 
Back
Top