TreeView - node indexing like an Array?

  • Thread starter Thread starter Arkion
  • Start date Start date
A

Arkion

Hello all!
Is there any way to refer to nodes in a TreeView's hierarchial
TreeNode structure by numeric indexes like with a simple Array?

I need to associate indexes with each node and be able to lookup nodes
using that index. Is there easier way to do this than recursively
iterating through the whole tree structure, looking for particular
index?
 
* Arkion said:
Is there any way to refer to nodes in a TreeView's hierarchial
TreeNode structure by numeric indexes like with a simple Array?

I need to associate indexes with each node and be able to lookup nodes
using that index. Is there easier way to do this than recursively
iterating through the whole tree structure, looking for particular
index?

You can add all your nodes to a datastructure like an 'ArrayList' to be
able to perform lookup of nodes by an index.
 
You can add all your nodes to a datastructure like an 'ArrayList' to be
able to perform lookup of nodes by an index.

I need to display this data structure in a TreeView control because of
it's hierarchial nature. How do you make TreeView do this, given each
node struct contains parent index and list of child indices? I also
need to be able to delete and add new nodes to the structure. This'll
make keeping indices in sync very tricky.

With Model-View-Controller separation this prolly would be a piece of
cake, but MVC concept isn't used in WinForms.
 
Hi Arkion,

Thanks for your feedback.

I think this is somewhat data structure issue, why not just use the Data
Structure of treenode? We may use TreeNode.Nodes property to loop through
one node's child node collection, also its Parent property gives us a
chance to refer its parent node. I think it will be difficult to write a
recusive program to loop through all the nodes in a treeview.

Also, if you have specified a index for each node, and you may store all
the treenodes' reference in a collection, such as ArrayList, then you can
use the index to find certain node's reference, which will save some
performance(Only when you have many treenodes).

If I did not catch your concern, please feel free to tell me.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Arkion,

Does my reply make sense to you? Is your problem resolved? Please feel free
to tell me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top