Since I am able to define several top-level nodes, I must conclude that a WebTree is only a real tree if these top-level nodes are attached to some common root node. I want access to this root node!
It is unnatural to treat the entire WebTree as something different as any other Node.
In my specific case, I have a method like this:
public void InsertMySubTree(Node parent) { foreach (...) { parent.Nodes.Add(...); ... } }
to insert my subtree into the WebTree at a certain point.
I can use it like this:
InsertMySubTree(tree.Nodes[2].Nodes[4].Nodes[1]);
This works fine as long as I don't want to insert my subtree at the top-level. Inserting at the top-level should just be a special case of inserting anywhere else in the tree. I should be able to do something like:
InsertMySubTree(tree.RootNode);
Hello,
This is a good question. I believe that if we had a real RootNode property, people would expect that this root node would also be displayed in the page and this way a treeview supporting multiple root nodes (the one you see in many interfaces like Windows Explorer for example) would seem not possible to achieve.
I personally like both suggestions here. For me, I typically find myself writing something similar for that if I want to use the same code (like same interface) and avoid the constant checking. I use the Nodes collection and add there, and the following method to abstract from root and child node
private TreeNodeCollection ParentNodeCollection(TreeNode node){ if (node.Level == 0) // root node { return treeView.Nodes; } else { return node.Nodes; }}
just a suggestion, how about
InsertMySubTree( null )
so if it doesn't have any parent, it should be at root level
That doesn't make sense.
It doesn't do the same thing as the method I described, and it has a different interface, which was the entire point: I want to be able to use a method with the same signature regardless of where in the tree I want to put things (the root or somewhere else). You know, the normal way to use a tree?
Nodes nodes = TaskTree.Nodes;Nodes nodes = node.Nodes;
InsertMySubTree(Nodes nodes);
public void InsertMySubTree(Nodes nodes) { foreach (...) { nodes.Add(...); ... } }
Just try this.