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
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.
PrivateSub RadButton1_Click(sender AsObject, e As EventArgs) Handles RadButton1.Click
Dim foundNode = TryCast(Me.RadTreeView1.Find("Mother"), RadTreeNode)
If foundNode IsNotNothingThen
foundNode.Selected = True
RadTreeView1.TreeViewElement.Scroller.ScrollToItem(foundNode)
foundNode.Expand()
EndIfEndSub
You can also check the attached project. Give it a try and let me know if it works for you.
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")