Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
140
WebTree as Node
posted

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);

or something similar. But there is no way to get a Node representing the real root of the WebTree.

Why??

Parents
No Data
Reply
  • 28464
    posted

    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;
        }
    }

Children
No Data