How to insert a Root Node in Tererik RadTreeView?

1.7k views Asked by At

I have a RadTreeView telerik control which is working great for me with Drag/Drop, Add, Rename and Delete functionalities. But I want to insert a root node which cannot be updated/rename and deleted.

2

There are 2 answers

0
Imran Qadir Baksh - Baloch On

This is the answer,

    protected void radTreeView_DataBound(object sender, EventArgs e)
    {
        RadTreeNode node = new RadTreeNode("Root", "-1");
        node.AllowEdit = false;
        node.Expanded = true;
        node.EnableContextMenu = false;
        node.PostBack = false;
        node.AllowDrag = false;
        var nodes = new List<RadTreeNode>();
        foreach (RadTreeNode n in radTreeView.Nodes)
        {
            nodes.Add(n);
        }
        node.Nodes.AddRange(nodes);
        radTreeView.Nodes.Clear();
        radTreeView.Nodes.Add(node);
    } 
0
Saritha.S.R On

Try this to add a root node in treeview.

protected void Page_Load(object sender, EventArgs e)
    {
        tree1.DataBind();
        RadTreeNode root = new RadTreeNode("Root");
        while (tree1.Nodes.Count > 0)
        {
            root.Nodes.Add(tree1.Nodes[0]);
        }
       tree1.Nodes.Add(root);
    }