How to select and expand specific node in radtreeview ?

1 Answer 103 Views
Treeview
Aravind
Top achievements
Rank 2
Iron
Iron
Iron
Aravind asked on 01 Jun 2023, 05:07 AM

Hi, i have radtreeview, in  that dynamically i loaded node upto 4 levels, from that i want to select and expand specific node only,

Here i attach sample treeview structure, from that i want to select and expand "11\20\8" and others should be collapsed by button click.



Please reply asap.

Regards
Aravind

1 Answer, 1 is accepted

Sort by
1
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 01 Jun 2023, 08:45 PM

Hello Aravind,

Thank you for the provided image.

In general, you can find the specific node, set its Selected property to true, and use the ScrollToItem() method of the Scrollerto bring it into view.

private void radButton1_Click(object sender, EventArgs e)
{
    var foundNode = this.radTreeView1.Find("Node59") as RadTreeNode;
    if (foundNode != null)
    {
        foundNode.Selected = true;
        this.radTreeView1.TreeViewElement.Scroller.ScrollToItem(foundNode);
    }
}

Give this approach a try and let me know if it works for you.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Aravind
Top achievements
Rank 2
Iron
Iron
Iron
commented on 02 Jun 2023, 07:14 AM

Hi,
  I can select and expand first level of node, i cant expand at 3r level. 
Example : This is treeview, in that i try to select and expand "Family\Father\Mother" it cant, in foundNode  i am getting nothing, If i give only "Family", then in node fullpath get "Family"


Dim foundNode = TryCast(Me.RadTreeView4.Find("Family\Father\Mother"), RadTreeNode) If foundNode IsNot Nothing Then foundNode.Selected = True RadTreeView4.TreeViewElement.Scroller.ScrollToItem(foundNode) foundNode.Expand() End If

Pls reply asap
Regards,
Aravind

Dinko | Tech Support Engineer
Telerik team
commented on 06 Jun 2023, 07:42 AM

The Find() method of the RadTreeView expects as a parameter the Text string property not the path of the node. If you pass the "Mother" string as a parameter, it will recursively search the tree for a node with the same Text property and return if a match is found.

Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
    Dim foundNode = TryCast(Me.RadTreeView1.Find("Mother"), RadTreeNode)
    If foundNode IsNot Nothing Then
        foundNode.Selected = True
        RadTreeView1.TreeViewElement.Scroller.ScrollToItem(foundNode)
        foundNode.Expand()
    End If
End Sub

You can also check the attached project. Give it a try and let me know if it works for you.

Aravind
Top achievements
Rank 2
Iron
Iron
Iron
commented on 23 Jun 2023, 10:53 AM

Hi, I forgot to ask , if "mother" node appears more than one place, then how ? which mother node will select and expand ?

_Family
     -Father
         -Mother
         -Son1
     -Neighbour
         -Mother
         -Son2
     -Neighbour1
         -Mother
         -Son2
Like above treeview, in which mother node is select and expanded  if use below code ?

Dim foundNode = TryCast(Me.RadTreeView1.Find("Mother"), RadTreeNode)
    If foundNode IsNot Nothing Then
        foundNode.Selected = True
        RadTreeView1.TreeViewElement.Scroller.ScrollToItem(foundNode)
        foundNode.Expand()
    End If

Regards
Aravind
Dinko | Tech Support Engineer
Telerik team
commented on 26 Jun 2023, 11:35 AM

The Find() method returns the first element which matches the string pass as a parameter. If you will have duplicate names, you can use the FindNodes(your string) method which returns all nodes whose name matches the one passed as a parameter. Then you can iterate the array and check the Parent property. If they are duplicated, you could create a recursion that gets all parents of each node and choose the desired one.

Dim allNodes = Me.RadTreeView1.FindNodes("Mother")

Tags
Treeview
Asked by
Aravind
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or