I know how to get the full path of a treeview node, but how do I do the reverse? ie. If I have a path to a node stored in a variable, how do I expand all the nodes in that path? Thanks...
Printable View
I know how to get the full path of a treeview node, but how do I do the reverse? ie. If I have a path to a node stored in a variable, how do I expand all the nodes in that path? Thanks...
if you have a reference to a TreeNode object in a variable, just call its .EnsureVisible method, and it will scroll and expand nodes as needed to make sure the given node is now visible in the control...
What if I dont have a reference to the node? I just know its .FullPath value. Do I have to iterate through the tree & match each node name to each folder name in the path?
Hi,Quote:
Originally Posted by nbrege
You can use the Treeview expand method.
The following code example toggles the selected node when a button is clicked. If the selected node is collapsed, it is expanded, if it is expanded by calling the Expand method, it is collapsed by calling the Collapse method. This example requires that you have a Form with a TreeView control that has at least one TreeNode with at least one child TreeNode.
Hope it helps,Code:Private Sub button1_Click(sender As Object, _
e As System.EventArgs) Handles button1.Click
If treeView1.SelectedNode.IsExpanded Then
treeView1.SelectedNode.Collapse()
MessageBox.Show(treeView1.SelectedNode.Text & _
" tree node collapsed.")
Else
treeView1.SelectedNode.Expand()
MessageBox.Show(treeView1.SelectedNode.Text & _
" tree node expanded.")
End If
End Sub
sparrow1
I don't know any specific way to reference a treenode via its fullpath property without looping the entire set of nodes in the treeview and doing a comparison...
I suppose you could parse out the full path into each node and select each node that is parsed out one by one until you get to the desired node.
Another option would be to make the "key" property of the treenode the fullpath of the node. This way you could use the .Find() method of the nodes collection and pass the fullpath, which would inturn find the node whose key matches.