all groups > dotnet windows forms > june 2007 >
You're in the

dotnet windows forms

group:

Treeview Index problem


Treeview Index problem B. Chernick
6/28/2007 7:56:02 AM
dotnet windows forms:
I'm trying to program a form with a treeview. I have just created a root
node in the control. Now I have called a routine to create a child node. As
I create these nodes I want to keep track of their indices in a data
structure. The code is roughly as follows:

(Assume the original root node is the selected node)

Dim tn As New TreeNode
tvAreas.SelectedNode.Nodes.Add(tn)
tvAreas.SelectedNode = tn

At this point I try to get the index of the selected node and it's always -1

I've tried both
i = tvAreas.SelectedNode.Index
and
i = tvAreas.Nodes.IndexOf(tvAreas.SelectedNode)

What's going on here?

RE: Treeview Index problem B. Chernick
6/28/2007 9:14:00 AM
My apologies, ignore the previous append. I was under the impression that
there was a master index for all nodes in a treeview, not just relative
indices for each node. (Of course, if this assumption is also wrong, please
feel free to correct me.)

[quoted text, click to view]
AddThis Social Bookmark Button