PDA

View Full Version : stepping through dotNet Treview nodes


floopyb
05-25-2011, 09:25 AM
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.

denisT
05-25-2011, 09:44 AM
Is there a method for easily stepping through all the nodes in a treeview other than making a recursive function to do it?

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.

Pjanssen
05-25-2011, 10:34 AM
If you want fast lookup based on an unique key, then a Dictionary<AnyTypeYouWant, TreeNode> is definitely the way to go.

floopyb
05-26-2011, 02:14 AM
Thanks guys, I might give the 1D array a go.


If you want fast lookup based on an unique key, then a Dictionary<AnyTypeYouWant, TreeNode> is definitely the way to go.

Could you explain this a bit more, i have no idea what it is :)

Pjanssen
05-26-2011, 07:00 AM
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).

http://msdn.microsoft.com/en-us/library/xfhwa508.aspx

CGTalk Moderation
05-26-2011, 07:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.