Treeview Key Property alternatives? (Half Resolved)
Is anyone else as fustrated as I am with the removal of the "key" property off of the Node object? What alternatives have you been using?
I thought about using the Tag property, but that doesn't really accomplish much because I can not retrieve the node by the Tag property, unless of course if I loop through each node to determine where it is and grab the index. This is not very efficient obviously.
Say for example you had to load a ton of data, maybe an entire domain of more than 25,000 users plus security groups each user is attached to (not what I'm doing but something done in the past). Hopefully you can see where this would be a problem.
Anybody have some good ways around this. I've seen a few people creating their own class that is inheriting either the node object or the tree object but none of them seem to be for this specific problem.
Thanks for any insight on what you are doing.
My slow, but working solution...
This is my working, although too slow in most cases, solution to my problem. I created the following function that excepts 2 parameters ndc (TreeNodeCollection) and iIndex (Integer). ndc is the obviously the Node Collection to start the search at (or when it's calling itself, the current Node Collection to be searched) and iIndex is the index I'm searching for (it could be changed to a string if you were storing some other value). The function returns a TreeNode object. Anyway, heres the code.
VB Code:
Friend Function GetNodeIndex(ByRef ndc As TreeNodeCollection, ByVal iIndex As Integer) As TreeNode
Dim nd As TreeNode
For Each nd In ndc
If nd.Tag = iIndex Then Return nd
Dim snd As TreeNode = GetNodeIndex(nd.Nodes, iIndex)
If Not IsNothing(snd) Then Return snd
Next
End Function
When I first ran this, I got several StackOverload Errors, but I've had none since that first attempt. Keep in mind however, I changed no code they just stopped. Feel free to use it or speed it up if you know a way (just let me know how to speed it up if you do :bigyello: )