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

Open Node

6 Answers 17 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 04 Jul 2014, 09:06 AM
Hi,

Unless I’m missing something obvious I can’t seem to find
a way to expand a treeview to a particular node?


Please advise?

TIA

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 04 Jul 2014, 09:56 AM
Hi Andy,

Try to use the client side expand method to expand a particular node. Please have a look into the sample code snippet which expands a node from JavaScript.

ASPX:
<telerik:RadTreeView ID="rtreeviewTestDemo" runat="server">
    <Nodes>
        <telerik:RadTreeNode Text="Node1">
            <Nodes>
                <telerik:RadTreeNode Text="Node1.1">
                </telerik:RadTreeNode>
                <telerik:RadTreeNode Text="Node1.2">
                </telerik:RadTreeNode>
            </Nodes>
        </telerik:RadTreeNode>
    </Nodes>
</telerik:RadTreeView>

JavaScript:
function pageLoad() {
    var node = $find("<%=rtreeviewTestDemo.ClientID%>");
    node.findNodeByText("Node1").expand();
}

Thanks,
Shinu.
0
Andy
Top achievements
Rank 1
answered on 04 Jul 2014, 10:12 AM
Thanks for the suggestions. Unfortunately I need to be able to do this server side, do
you have a C# example please?

0
Shinu
Top achievements
Rank 1
answered on 04 Jul 2014, 10:33 AM
Hi Andy,

Please try the below C# code snippet.

C#:
RadTreeNode node = rtreeviewTestDemo.Nodes.FindNodeByText("Node1") as RadTreeNode;
node.Expanded = true;

Thanks,
Shinu.
0
Andy
Top achievements
Rank 1
answered on 04 Jul 2014, 02:27 PM
Hi,

Thanks for the suggestion, unfortunately it does not expand the treeview?
0
Shinu
Top achievements
Rank 1
answered on 07 Jul 2014, 02:51 AM
Hi Andy,

Unfortunately I couldn't replicate the issue at my end. In order to expand a node try to set the Expanded property and ExpandChildNodes & ExpandParentNodes methods are there to expand the child node and parent node of a RadTreeNode. Please have a look into the sample code snippet which works fine at my end.

ASPX:
<telerik:RadTreeView ID="rtreeviewTestDemo" runat="server">
    <Nodes>
        <telerik:RadTreeNode Text="Node1">
            <Nodes>
                <telerik:RadTreeNode Text="Node1.1">
                    <Nodes>
                        <telerik:RadTreeNode Text="Node1.11">
                        </telerik:RadTreeNode>
                        <telerik:RadTreeNode Text="Node1.12">
                        </telerik:RadTreeNode>
                    </Nodes>
                </telerik:RadTreeNode>
                <telerik:RadTreeNode Text="Node1.2">
                </telerik:RadTreeNode>
            </Nodes>
        </telerik:RadTreeNode>
    </Nodes>
</telerik:RadTreeView>

C#:
protected void Page_Load(object sender, EventArgs e)
{
    RadTreeNode parentNode = rtreeviewTestDemo.Nodes.FindNodeByText("Node1") as RadTreeNode;
    RadTreeNode childNode = parentNode.Nodes.FindNodeByText("Node1.1") as RadTreeNode;
    parentNode.ExpandChildNodes();
    childNode.ExpandParentNodes();
}

Please provide your code if it doesn't help.
Thanks,
Shinu.
0
Doug
Top achievements
Rank 1
answered on 01 Aug 2014, 09:15 PM
I expand each with a loop that travels up the tree

Dim node As RadTreeNode = RadTreeView1.FindNodeByAttribute("CategoryId", Request.QueryString("CategoryID"))
If Not IsNothing(node) Then
   node.Selected = True
   node.Expanded = True
   ...
End If
While (Not IsNothing(node))
    node.ExpandParentNodes()
    ...
node.ExpandMode = TreeNodeExpandMode.ClientSide
node = node.ParentNode
End While
Tags
TreeView
Asked by
Andy
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Andy
Top achievements
Rank 1
Doug
Top achievements
Rank 1
Share this question
or