need to get hierarchy in treeview

  • Thread starter Thread starter Co
  • Start date Start date
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
 
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 = "\"
 
Back
Top