Don,
Look carefully at how the TreeView Nodes are owned.
The TreeView itself only owns the root nodes, with indexes from 0 to however
many root nodes.
Each root node will own their children, their children will have indexes
from 0 to however many children each respective root has.
The grand children (of root) will have indexes from 0 to however many
children each parent (child of root) has respectively.
And so on.
In other words all the nodes in the following will have an index of 0,
except Grand Child 2 & Root 2 which will have indexes of 1.
Root 1 (index = 0)
Child 1 (index = 0)
Grand Child 1 (index = 0)
Great Grand Child 1 (index = 0)
Grand Child 2 (index = 1)
Great Grand Child 2 (index = 0)
Child 2 (index = 0)
Grand Child 3 (index = 0)
Great Grand Child 3 (index = 0)
Root 2 (index = 1)
Child 3 (index = 0)
Grand Child 4 (index = 0)
Great Grand Child 4 (index = 0)
If you need to index the nodes by both Key & Index, where Index is across
all nodes in the tree) I would recommend a
System.Collections.Specialized.NameValueCollection instead of a HashTable.
As the NameValueCollection supports indexing by both Key & Index.
Hope this helps
Jay
"Don Wash" <do*@wash.com> wrote in message
news:On*************@TK2MSFTNGP11.phx.gbl...
Thanks, I've tried HashTable method but it doesn't seems to work.
Here's the code...
With objNewNode
htMain.Add(strNodeKey, .Index)
htMain_IndexToKey.Add(.Index, strNodeKey)
.Text = "Node Item " & i
.ImageIndex = 1
End With
.Nodes.Add(objNewNode)
htMain and htMain_IndexToKey are HashTable objects. What happens is that
Index of objNewNode is always '0' (Zero).
So I though objNewNode is an independent TreeView Node which hasn't been
associated with the real TreeView control and I tried this code instead...
Dim intNodeIndex as Integer = .Nodes.Add(objNewNode)
htMain.Add(strNodeKey, intNodeIndex )
htMain_IndexToKey.Add(intNodeIndex , strNodeKey)
and still intNodeIndex equal '0' every time. How can I get the actual
Node's index currently being added to the TreeView Nodes collection?
Thanks again!
Don
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ey**************@tk2msftngp13.phx.gbl... * "Don Wash" <do*@wash.com> scripsit: I'm using VB.NET to create a TreeView application and unfortunately I could not find "Key" property in Node items of the TreeView.
There is no direct replacement for this property. You can set up a
'Hashtable' and store your (key, 'TreeNode') pairs for fast lookup by a
key there.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>