Solved

Posted on 2008-11-11
1,301 Views
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?

0
Question by:tonelm54

LVL 20

Expert Comment

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 Comment

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

LVL 20

Accepted Solution

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

Author Comment

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

## Featured Post

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…