need to get hierarchy in treeview

C

Co

Hi All,

I have a treeview with some nodes.
I want to show the hierarchy of a node when I click on it.
I tried with following code but it doesn't do what I want:

Private Sub RecurseNodes(ByVal col As TreeNodeCollection)
For Each tn As TreeNode In col
MsgBox(tn.Text)
If tn.Nodes.Count > 0 Then
RecurseNodes(tn.Nodes)
End If
Next tn
End Sub

It does list all names but in the wrong order.

What I need is following:
let's say my treeview:

Kabinet
|--------Level1
| |-------- Level2

Now I want to display on a label: Kabinet\Level1\Level2 when I click
on the Level2 node.

Marco
 
T

Teme64

Co said:
Hi All,

I have a treeview with some nodes.
I want to show the hierarchy of a node when I click on it.
I tried with following code but it doesn't do what I want:

Private Sub RecurseNodes(ByVal col As TreeNodeCollection)
For Each tn As TreeNode In col
MsgBox(tn.Text)
If tn.Nodes.Count > 0 Then
RecurseNodes(tn.Nodes)
End If
Next tn
End Sub

It does list all names but in the wrong order.

What I need is following:
let's say my treeview:

Kabinet
|--------Level1
| |-------- Level2

Now I want to display on a label: Kabinet\Level1\Level2 when I click
on the Level2 node.

Marco

Use FullPath property:

Private Sub TreeView1_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick
'
MessageBox.Show(e.Node.FullPath, "Full Path", MessageBoxButtons.OK, MessageBoxIcon.Information)

End Sub

Set the path separator:

TreeView1.PathSeparator = "\"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top