Link to home
Start Free TrialLog in
Avatar of tonelm54
tonelm54

asked on

VB.net TreeView find node

Im playing with the treeview control, but cant find if a particular path exists,

What Im trying to do is test if a particular path exists from root and return yes or no.

To try and test my idea, ive written the code below which should give the msgbox "Found path!"

Any ideas?
TreeView1.Nodes.Add("Nodes_1").Nodes.Add("Nodes_1.1").Nodes.Add("Nodes_1.1.1")
        If TreeView1.Nodes.Find("Nodes_1\Nodes1.1\Nodes_1.1.2", False) Is Nothing Then
            MsgBox("Not Found!")
        Else
            MsgBox("Found path!")
        End If

Open in new window

Avatar of Juan_Barrera
Juan_Barrera
Flag of New Zealand image

Hi again!

Look, this works for me, have a look:

 Dim tv As New TreeView
        Dim root As New TreeNode("Personal")
        tv.Nodes.Add(root)
        Dim child1 As New TreeNode("Banking")
        root.ChildNodes.Add(child1)
        Dim child2 As New TreeNode("Insurance")
        root.ChildNodes.Add(child2)
        Dim child3 As New TreeNode("Alliance and Leicester")
        child1.ChildNodes.Add(child3)
        Dim fn As TreeNode = tv.FindNode("Personal/Banking/Alliance and Leicester")
        If fn IsNot Nothing Then
            MsgBox("Found path!")
        Else
            MsgBox("Not Found!")
        End If

Open in new window

Avatar of tonelm54
tonelm54

ASKER

lol, Hi I opened a new question to go along another idea path.

When I try and run your code I get:-
          'ChildNodes' is not a member of 'System.Windows.Forms.TreeNode'.
ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@jpaulino,

Yes! I've just noticed that and was about to upload a snippet for WinForms. Points for you then! :)
Kool, that works!

Thank you