TreeNodes
-
I have a recursive call to a treeview as such: foreach (TreeNode n in nodes) { do something } How can I get this to work fall all nodes except the TopNode? Thanks in Advance. D
-
instead of foreach(treenode n in nodes) { } u cld do the coding wotever u wanna do.."for those levels".. so in tat case, u cld not do it for the topnode level.. i guess this shld do.. try it..
create your root node then call the recursive function to return a treenode collection with root as parent as all nodes can be a subtree, this can also work by recursilvely calling itself and returning a subtree with its caller as the root, eventually the root(top initial root) node will end up with all subtrees as its children have just finished a similar problem to this, gotta love recursion :-) regards, g00fy
-
create your root node then call the recursive function to return a treenode collection with root as parent as all nodes can be a subtree, this can also work by recursilvely calling itself and returning a subtree with its caller as the root, eventually the root(top initial root) node will end up with all subtrees as its children have just finished a similar problem to this, gotta love recursion :-) regards, g00fy
-
Thanks for your help. But how do I return the root as the parent? the root node is displayed when the form is generated. However, there are no child nodes until the user drags-and-drops to the corresponding treeview. Thanks again.
i thought you wanted to exclude the root node, that is the initial root node. you should just be adding to it with your recursive call like
rootNode.Nodes.Add(GetSubTree());
if you want the root, the easiest way is to code it and hold a reference to it ... or ... get it from tree.Nodes collection hth g00fy -
i thought you wanted to exclude the root node, that is the initial root node. you should just be adding to it with your recursive call like
rootNode.Nodes.Add(GetSubTree());
if you want the root, the easiest way is to code it and hold a reference to it ... or ... get it from tree.Nodes collection hth g00fy -
Thanks for the speedy response. You were right, I want to exclude the topnode or root node. I want to make changes to all of the child nodes, not the topnode. How will adding the GetSubTree exclude the topnode? Thanks again for all of your help.
get subtree is your recursive call that is building the subtree/s then you add that to the node collection of the rootnode just a quick eg of top of head
private TreeNode root; public void Test() { root = new TreeNode("root"); root.Nodes.Add(GetSubTree()); this.treeView1.Nodes.Add(root); } int i = 0; private TreeNode GetSubTree() { TreeNode subtree = new TreeNode("x: " + i); while(i++ < 10) { root.Nodes.Add(new TreeNode("node: " + i)); return GetSubTree(); } return subtree; }
hth g00fy -
get subtree is your recursive call that is building the subtree/s then you add that to the node collection of the rootnode just a quick eg of top of head
private TreeNode root; public void Test() { root = new TreeNode("root"); root.Nodes.Add(GetSubTree()); this.treeView1.Nodes.Add(root); } int i = 0; private TreeNode GetSubTree() { TreeNode subtree = new TreeNode("x: " + i); while(i++ < 10) { root.Nodes.Add(new TreeNode("node: " + i)); return GetSubTree(); } return subtree; }
hth g00fy