vb.net TreeView Add nodes

Good evening,
I know how to add nodes to a treeview in vb.net, but need some help looking at an algorithm to add nodes.

In my navigation table I have the following rows:-
          Personal \ Banking\ Alliance and Leicester
          Personal \ Banking\ Barclays
          Personal \ Banking\ Natwest
          Personal \ Insurance \ Home \ Direct Line '98
          Personal \ Insurance \ Home \ Tescos '98
          Personal \ Insurance \ Home \ Direct Line '98
          Personal \ Insurance \ Car \ Tescos '99

Problem is, if I just add these nodes, I get 7 root nodes, instead of 1 root node, and 2 children etc.

Any ideas how I can write these nodes correctly?

Thanks in advance!
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 there,

Here is an example:

    Dim tv As New TreeView
        Dim root As New TreeNode("Personal")
        Dim child1 As New TreeNode("Banking")
        Dim child2 As New TreeNode("Insurance")

Open in new window

tonelm54Author Commented:
thats ok, but the amount of rows I have is in excess of 1000, and go several deep, so I need an algorithm to test if each node exists if it does move to child and add if doesnt exist.

So something like
writeNodes("Personal \ Insurance \ Home \ Tescos '98")

sub writeNodes(strNodePath as string)
     eachBranch = split(strNode,"\")
     for each eachBranch
          if nodeexists = false
               add node
          end if
     next eachBranch
end sub

Sorry for the phudeo code, but I dont know how to seach if a node exists, so if possible test weather the tree branch exists:-
               Direct Line '98

return true or false.

Sorry if this doesnt sound right!
Before trying that, wouldn't be better to convert your rows into XML and bond the TreeView to an XmlDataSource?

Anyway, you can use tv.FindNode("path") to check if a node exists, which may slove your problem.

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
tonelm54Author Commented:
Yup I could use a data source, however looking into databinding the control it wont support different levels of children.

For example some branches can have children with children with children with children with children with children with children with children, and some branches just have 1 child.
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.