Click here to Skip to main content
13,257,667 members (78,242 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I want to set treeView.selectedNode programlly in C# and I want to be occured the beforeSelect event while proccessing this assigning. but my question is what I describe below:
when I use the code bellow, the beforeSelect event occured and call it's function.

this.treeView1.SelectedNode = treeView1.Nodes[Level1Index];

but when I use such as bellow It doese'nt occure.

this.treeView1.SelectedNode = treeView1.Nodes[Level1Index].Nodes[Level2Index];

Posted 27-Mar-13 1:14am
Updated 27-Mar-13 2:29am
Richard MacCutchan 27-Mar-13 7:30am
Impossible to tell, you need to provide some more information about the actual valuse of your variables at the time this code is executed.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You should assign your obtained nodes into variables so that you can see their content while debugging (F5).

TreeViewNode node1 = treeView1.Nodes[Level1Index];
TreeViewNode node2 = treeView1.Nodes[Level2Index];

From here, see in the the debugger what your node1 and node2 variables contain ; you will have a better understanding about your problem.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I double checked, your scenario and when the SelectedNode is set regardless of its hierarchy, it always trigger the BeforeSelected event.

It is most likely that the
is null. if it is null then the node will not be selected and so the BeforeSelected event will not be triggered.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171114.1 | Last Updated 27 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100