Reputation: 539
I think this is common in treeview, it has a number of level, and I have a path, say:
Level1 > Level2 > Level3 > Level4
How can I expand the treeview to Level 4 by using the path? Any built-in function?
Thanks.
Upvotes: 4
Views: 4028
Reputation: 1
Try this:
Private Sub Expand(ByVal sPath As String)
Dim objNode As TreeNode
Dim preNode As TreeNode = tFolder.Nodes(0)
preNode.Expand()
Dim sSpl() As String = sPath.Replace("\\", "\").Split("\")
For i As Integer = 1 To sSpl.Length - 1
For Each objNode In preNode.Nodes
If objNode.Text = sSpl(i) Then
objNode.Expand()
preNode = objNode
Exit For
End If
Next
Next
End Sub
Upvotes: 0
Reputation: 3924
If this question is still common...
node.ExpandParentNodes();
This will go through parent using recursion and expand.
Upvotes: 0
Reputation: 33474
Purely based on documentation
TreeNode mynode = treeView1.FindNode(pathToNode);
mynode.Select();
mynode.Expand();
I hope you get the starting point from here.
Upvotes: 2