André,
In addition to the other comments.
You could "walk" the Node.Nodes collection to find your node of interest.
However depending on the amount of data & how often I wanted to select a
specific node I might go with the other suggestion.
Here's a custom Tree View that adds a SelectedPath property, instead of
putting a TreeView on your Form, put a MyTreeView (I will add a TreeView in
the designer then carefully change System.Windows.Forms.TreeView to
MyTreeView), then in code or the properties window enter the path of the
requested Node.
Option Strict On
Option Explicit On
Public Class MyTreeView
Inherits TreeView
<System.ComponentModel.DefaultValue("")> _
Public Property SelectedPath() As String
Get
If MyBase.SelectedNode Is Nothing Then
Return String.Empty
Else
Return MyBase.SelectedNode.FullPath
End If
End Get
Set(ByVal value As String)
If value = String.Empty Then
MyBase.SelectedNode = Nothing
Exit Property
End If
Dim paths() As String = Split(value, MyBase.PathSeparator)
Dim nodes As TreeNodeCollection
Dim node As TreeNode
For Each path As String In paths
If nodes Is Nothing Then
nodes = MyBase.Nodes
ElseIf Not node Is Nothing Then
nodes = node.Nodes
End If
For Each child As TreeNode In nodes
If child.Text = path Then
node = child
Exit For
End If
Next
Next
If value = node.FullPath Then
MyBase.SelectedNode = node
Else
Throw New ArgumentOutOfRangeException("SelectedPath", value,
"SelectedPath not found")
End If
End Set
End Property
End Class
Hope this helps
Jay
"André Nogueira" <an**@netcabo.pt.NOSPAM> wrote in message
news:ek**************@TK2MSFTNGP15.phx.gbl...
Hi there.
I know you can view a node's fullpath property, but is it posible to
select a node using its path?
Like, tell the treeview that the node that should be selected is the node
with the path "Users\Administrators\John Doe"?
Thank you in advance!
Andre Nogueira