Home All Groups Group Topic Archive Search About

Treeview SelectedNodeChanged event not firing

Author
14 Mar 2006 9:43 PM
Brad Law
--
Brad

Hello - I'm having the following code to trigger when any treeview node is
selected:

On Page_load:

this.TreeView1.SelectedNodeChanged += new
System.EventHandler(this.TreeView1_Select);

public void TreeView1_Select(object sender, System.EventArgs e)
    {
        string value = TreeView1.SelectedNode.Value;
        string path = TreeView1.SelectedNode.ValuePath;

    }

But the Treeview1_select is not getting triggered at all.  Instead when a
node is clicked, a new page with the same treeview shows up.

Any help is appreciated.

Thanks

Author
14 Mar 2006 11:01 PM
Phillip Williams
Set the NavigateUrl property of the TreeNode to an empty string:

"The text of a node in the TreeView control can be in one of two modes:
selection mode or navigation mode. By default, a node is in selection mode.
To put a node into navigation mode, set the node's NavigateUrl property to a
value other than an empty string (""). To put a node into selection mode, set
the node's NavigateUrl property to an empty string." http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.treenode(VS.80).aspx

Show quoteHide quote
"Brad Law" wrote:

>
> --
> Brad
>
> Hello - I'm having the following code to trigger when any treeview node is
> selected:
>
> On Page_load:
>
> this.TreeView1.SelectedNodeChanged += new
> System.EventHandler(this.TreeView1_Select);
>
> public void TreeView1_Select(object sender, System.EventArgs e)
>     {
>         string value = TreeView1.SelectedNode.Value;
>         string path = TreeView1.SelectedNode.ValuePath;
>
>     }
>
> But the Treeview1_select is not getting triggered at all.  Instead when a
> node is clicked, a new page with the same treeview shows up.
>
> Any help is appreciated.
>
> Thanks
>
Author
15 Mar 2006 11:18 AM
CaffieneRush@gmail.com
You can also control what happens when the nodes are selected with
TreeNode's SelectAction property. It accepts a TreeNodeSelectAction
enum.

Public Enum TreeNodeSelectAction
      ' Fields
      Expand = 1
      None = 3
      [Select] = 0
      SelectExpand = 2
End Enum

So if you want ONLY your leaf nodes to raise the Select event then set
those nodes' SelectAction property to TreeNodeSelectAction.Select and
set the other nodes to TreeNodeSelectAction.Expand.