Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Treeview
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];
this.treeView1.SelectedNode=treeView1.SelectedNode.Nodes[Level2Index];
 
but when I use such as bellow It doese'nt occure.
 
this.treeView1.SelectedNode = treeView1.Nodes[Level1Index].Nodes[Level2Index];
why?
Posted 27-Mar-13 1:14am
Edited 27-Mar-13 2:29am
v3
Comments
Richard MacCutchan at 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
good
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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
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
treeView1.Nodes[Level1Index].Nodes[Level2Index];
is null. if it is null then the node will not be selected and so the BeforeSelected event will not be triggered.
 
Regards
Jegan
  Permalink  
v2

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

  Print Answers RSS
0 Marcin Kozub 330
1 OriginalGriff 256
2 Sergey Alexandrovich Kryukov 215
3 Praneet Nadkar 197
4 Richard MacCutchan 182
0 OriginalGriff 8,048
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 27 Mar 2013
Copyright © CodeProject, 1999-2014
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