This is a migrated thread and some comments may be shown as answers.

Expand TreeNode at Server Side

1 Answer 63 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Phaneendra
Top achievements
Rank 1
Phaneendra asked on 28 Apr 2012, 04:03 PM
Hi,
In my aspx page, left side I'm displaying Treeview, right side a Panel which nodes for creating new node.
I'm Creating Treeview dynamically.
I have a Treeview context menu for creating new node.
When user creates new node using context menu(user provides details on right side), and clicks on create, that nodes should be created and that node path to be expanded and selected.
I 've tried like this

string NewNodeName = ViewState["NewChart"] != null ? ViewState["NewChart"].ToString() : string.Empty;
           foreach (RadTreeNode node in TreeLubeChart.GetAllNodes())
           {
               if (node.Text == NewNodeName)
               {
                   node.Selected = true;
                   node.Expanded = true;
               }
           }
But this is not making my work done. I placed this under button click where new node is created, but New node which user provides is creating, but I need its path to be expanded and selected state.


Thanks
Krishna

1 Answer, 1 is accepted

Sort by
0
Accepted
Plamen
Telerik team
answered on 02 May 2012, 01:48 PM
Hi Phaneedra,

 
You can refer to this online demo and add the following code in yellow that expands all the parent nodes when a node is added:

protected void AddButton_Click(object sender, EventArgs e)
        {
            Page.Validate("TextRequired");
            if (Page.IsValid)
            {
                IRadTreeNodeContainer target = RadTreeView1;
                if (RadTreeView1.SelectedNode != null)
                {
                    RadTreeView1.SelectedNode.Expanded = true;
                    target = RadTreeView1.SelectedNode;
                }
                     
 
                RadTreeNode addedNode = new RadTreeNode(NodeTextBox.Text);
                addedNode.Selected = true;
                target.Nodes.Add(addedNode);
 
                RadTreeNode parentNode = addedNode.ParentNode;
                while (parentNode != null)
                {
                    parentNode.Expanded=true;
                    parentNode = parentNode.ParentNode;
                }
 
            }
        }

Hope this will help you.


Kind regards,
Plamen Zdravkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
TreeView
Asked by
Phaneendra
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or