Hello,
I am trying to get all the nodes in my Win Tree Control as a TreeCollection. Just unable to figure out which member will return this to me. Also is there a way to get the number of levels within the Win Tree?. It would be ideal if there is a API which can take the level I pass to it and return me the nodes on that level as a TreeCollection. Let me know your thoughts. Thanks.
Hi,
The Nodes in the WinTree are not stored in a single collection, you would need to walk through the nodes and their child nodes recursively to get all of them.
Is there an example somewhere on how to walk through the nodes? Thanks.
Look into this resource. I found it useful. The IterateNodes Subroutine might help you.
<http://help.infragistics.com/Help/NetAdvantage/NET/2007.3/CLR2.0/html/WinTree_Nodes_Overview.html>.
-Saravanan.
Just use recursion:
private List<Node> allnodes = new List<Node>();
foreach (Node ne in ultraTree.Nodes){ allnodes.Add(ne); if (ne.Nodes.Count > 0) WalkTree(allNodes, ne);}
private void WalkTree(List<Node> allnodes, Node parent){ foreach(Node n in parent.Nodes) { allNodes.Add(n); if (n.Nodes.Count > 0) WalkTree(allNodes, n); }}
I didn't run this or anything but something like this should work, not sure if its the easiest way or not. Or look up walking a tree in Google.