Setting Treeview Index

  • Thread starter Thread starter Kelvin Bryant
  • Start date Start date
K

Kelvin Bryant

I have tried the following code to set the index for a
node. It seems to work when I use the root node index of
0. When I try a number greater than 0 I get an out of
range error. I made sure that the tree was expanded, as
well.

treeView1.Focus();
treeView1.SelectedNode = treeView1.Nodes[1];
 
Kelvin,

How many nodes are there under the root? I think that the Nodes that
are being exposed is the top level of nodes, and not all of the nodes in the
tree. If you have only one node at the root, then this would definitely
fail.

Hope this helps.
 
Kelvin Bryant said:
I have tried the following code to set the index for a
node. It seems to work when I use the root node index of
0. When I try a number greater than 0 I get an out of
range error. I made sure that the tree was expanded, as
well.

treeView1.Focus();
treeView1.SelectedNode = treeView1.Nodes[1];

Note that treeView1.Nodes is only the list of nodes branching off the root;
not all the nodes in the entire tree.

treeView1.Nodes[1].Nodes is the list of nodes that branch off node 1, and so
forth. It's a recursive data structure.
 
Yes, you are on to something! My structure is as such:
Root Node
Parent Node 1
Child Node 1
Child Node 2
Child Node 3
Parent Node 2
Child Node 1
Child Node 2
Blah Blah Blah
-----Original Message-----
Kelvin,

How many nodes are there under the root? I think that the Nodes that
are being exposed is the top level of nodes, and not all of the nodes in the
tree. If you have only one node at the root, then this would definitely
fail.

Hope this helps.


I have tried the following code to set the index for a
node. It seems to work when I use the root node index of
0. When I try a number greater than 0 I get an out of
range error. I made sure that the tree was expanded, as
well.

treeView1.Focus();
treeView1.SelectedNode = treeView1.Nodes[1];


.
 
Back
Top