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

Problem in expanding parent node of Treeview

1 Answer 266 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Arunshyam
Top achievements
Rank 1
Arunshyam asked on 29 Nov 2011, 06:11 PM
Hi,

Help me to solve this problem.

I have a treeview in that I'am binding the nodes based on demand. When page load, i will load level1 treenodes and when expanding the level1 treenode im loading the level2 nodes using treenode value. And in another case I will bind the treeview when user enters a text from textbox.  Here I want to expand all the parent node of the user entered text. In my code its expanding the node what user entered from textbox and its child nodes. But its not expanding the parent node of what user entered from textbox.

I need treeview like as attached image.

My Control:

<

telerik:RadTreeView ID="RadTreeViewCodeTypes" runat="server" OnNodeExpand="RadTree_OnNodeExpand"

 

Skin="HCPro" EnableEmbeddedSkins="false" Width="245px" OnNodeClick="RadTree_OnNodeClick"

Style="white-space: normal" SingleExpandPath="true" >

 

<DataBindings>

 

<telerik:RadTreeNodeBinding Expanded="false" ExpandMode="ServerSide"/>

 

</DataBindings>

 

</telerik:RadTreeView>
Code behind:

RadTreeViewCodeTypes.DataFieldID = "ID";

RadTreeViewCodeTypes.DataFieldParentID = "ParentCode";
RadTreeViewCodeTypes.DataTextField = "TextCode";

RadTreeViewCodeTypes.DataValueField = "ID";

 RadTreeViewCodeTypes.DataSource = TreeviewList;

RadTreeViewCodeTypes.DataBind();

after this binding

foreach (RadTreeNode node in RadTreeViewCodeTypes.GetAllNodes())

{

 if (node.Value == Session["SearchCode"].ToString())

 { 

if (!node.Expanded)  

{
node.ParentNode.ExpandChildNodes();

node.Selected = true;  

RadTreeNode Node = new RadTreeNode(); 

Node = node.ParentNode;
while (Node.ParentNode != null)

{

 

Node.Expanded = true;

Node = Node.ParentNode;

}

node.Selected = true;

}

}

}

Thanks,
Arunshyam. S

1 Answer, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 05 Dec 2011, 09:05 AM
Hi Arunshyam,

If I understand you right you are trying to expand all the parent nodes of the node whose name is typed in the textbox. You can try this code:
RadTreeNode parent = node.ParentNode;
 
while (parent != null) {
 
    parent.Expanded = true;
 
    parent = parent.ParentNode;
 
}

Hope this will be helpful.

Best wishes,
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
Arunshyam
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or