Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TreeView (node.SelectAction)

Status
Not open for further replies.

bobetko

Programmer
Jan 14, 2003
155
US
What event is raised when user click on already selected node in the tree? There is no OnClick (server side) events. I tried to assign action (TreeNodeSelectAction.Select) to every node, but I don't know how to handle event then.

In the help pages, it is clearly said that TreeNodeSelectAction.Select raises
SelectedNodeChanged event. So how to capture node's SelectedNodeChanged event?

Thanks.
 
Take a look at this [Link] ]MSN article [/url] (if you haven't already seen it).

A few quotes from other sources:
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.

Another example:
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)
    {
        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);
            }
        }
    }
Just a couple of tidbits I picked up off the web; personally I have not used the TreeView -- thought there might be something here that might help.
 
Thanks for your response...

Today I have red all web pages on the google that have keywords "treeview asp net", and that's a lot.

I populate my tree programatically from database. Everything work fine except one thing. It is important to me to capture click event every time when node is clicked. SelectedNodeChanged event is triggered only when you select different node, but if you click on the same node (that is ALREADY SELECTED) no event is triggered. Node.NavigateUrl is set to empty string which means that tree is doing postback. After reading all these pages it seems to me that capturing OnClick is not possible. I simply can't believe it.
On the Microsoft website I found that I can assign action to every of my nodes:

Code:
...
mynode.SelectAction = TreeNodeSelectAction.Select;
...

TreeNodeSelectAction.Select should raise SelectedNodeChanged event (it doesn't say will it happen if node is already selected). Anyway, I couldn't make it work.
How am I supposed to name function which will handle this node event? Something like
protected void node_SelectedNodeChanged(){...}[\b], or ...??

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top