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?
        If TreeView1.Nodes.Find("Nodes_1\Nodes1.1\Nodes_1.1.2", False) Is Nothing Then
            MsgBox("Not Found!")
            MsgBox("Found path!")
        End If

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi again!

Look, this works for me, have a look:

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

Open in new window

tonelm54Author Commented:
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'.
Jorge PaulinoIT Pro/DeveloperCommented:
That's for ASP.NET not winforms, right ?
Check this example (snippet).
Nodes.Find finds by the key and not on the text. You can include the path on the key and leave the text as you need. Then you can find by full path.

' Adds the node
Dim node As TreeNode = TreeView1.Nodes.Add("Nodes_1", "Nodes_1")
node.Nodes.Add("Nodes_1\Nodes_1.1", "Nodes_1.1").Nodes.Add("Nodes_1\Nodes_1.1\Nodes_1.1.1", "Nodes_1.1.1")
' Finds by full path
Dim node() As TreeNode = TreeView1.Nodes.Find("Nodes_1\Nodes_1.1\Nodes_1.1.1", True)
If node.Length > 0 Then
End If

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

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

Thank you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.