[Closed] stepping through dotNet Treview nodes
Is there a method for easily stepping through all the nodes in a treeview other than making a recursive function to do it?
I want to check certain nodes based on values in the node.tag, i dont care where they are, I just want an easy way to go through all of them, like a listview.
there is no other than a recursive search method for it. build-in find method uses a recursion as well. that’s why for some my controls I make extra one-dimensional array with pointers to tv nodes to have an easy access.
If you want fast lookup based on an unique key, then a Dictionary<AnyTypeYouWant, TreeNode> is definitely the way to go.
Thanks guys, I might give the 1D array a go.
Could you explain this a bit more, i have no idea what it is
Sure. A Dictionary is a collection type which allows you to look up objects using a (unique) key. Like you do in a real dictionary, where the word you look for is the key, and the text explaining the meaning or translation is object you want to find.
This means that you don’t have to loop through an array and perform a test on each object to find the one you need. For example if you have treenodes for objects in your 3dsmax scene, and you want to find a specific treenode when an object is selected, you can use the objects handle as a key:
Your dictionary would then be a Dictionary<Int32, TreeNode>, where the Int32 is the type of the key (the node handle). To find a treenode, you could use either myDict[handle], or myDict.TryGetValue(handle, out tn).