Completed
Last Updated: 25 Jun 2018 10:07 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 24 May 2018 05:21
Category: TreeView
Type: Feature Request
2
ADD. RadTreeView - add the option to add a root node via the context menu
Workaround:

        class CustomTreeView : RadTreeView
        {
            //Replace the default element with the custom one
            protected override RadTreeViewElement CreateTreeViewElement()
            {
                return new CustomTreeViewElement();
            }

            //Enable theming for the control
            public override string ThemeClassName
            {
                get
                {
                    return typeof(RadTreeView).FullName;
                }
            }
        }

        class CustomTreeViewElement : RadTreeViewElement
        {
            //Enable themeing for the element
            protected override Type ThemeEffectiveType
            {
                get
                {
                    return typeof(RadTreeViewElement);
                }
            }

            protected override bool ProcessContextMenu(Point location)
            {
                RadTreeNode node = this.GetNodeAt(location);
                if (node == null)
                {
                    RadContextMenu menu = new RadContextMenu();
                    RadMenuItem item = new RadMenuItem();
                    item.Text = "Add a root node";
                    menu.Items.Add(item);
                    item.Click += item_Click;
                    TreeViewContextMenuOpeningEventArgs args = new TreeViewContextMenuOpeningEventArgs(node, menu);
                    OnContextMenuOpening(args);

                    if (!args.Cancel)
                    {
                        menu.Show(this.ElementTree.Control, location);
                        return true;
                    }
                }
                return base.ProcessContextMenu(location);
            }

            private void item_Click(object sender, EventArgs e)
            {
                this.Nodes.Add(new RadTreeNode("New root"));
            }
        }
2 comments
ADMIN
Hristo
Posted on: 25 Jun 2018 10:07
Hi Patrick,

The issue was fixed in the R2 SP1 2018 release, if possible please upgrade to the latest version.

Regards,
Hristo
Patrick
Posted on: 25 May 2018 14:17
I was able to just add a regular level node but then set the parent ID to 0 in the code and then reload the tree and it worked.  Seems like something that should be built in to add a root node from menu.  Thanks for submitting.

I also then set the selected node to the new root node and it doesn't show as selected even though in code debugging watch window it says it is selected.