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?

###### Who is Participating?

x
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.

Commented:
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")
``````
0
Author 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
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:-
Personal
Insurance
Home
Direct Line '98

return true or false.

Sorry if this doesnt sound right!
0
Commented:
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.
0

Experts Exchange Solution brought to you by