How to populate TreeView with controls from Form?

G

Guest

I've figured out how to enumerate through all the controls in a form
(code below) However, how would I populate the TreeView with control
names in correct hierarchial order?


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim c As Control
TreeView1.BeginUpdate()
TreeView1.Nodes.Clear()
For Each c In Me.Controls
iterate(c)
Next
TreeView1.EndUpdate()
End Sub

Private Sub iterate(ByVal c As Control)
TreeView1.Nodes.Add(c.Name) ' adds all the controls w/o
hierarchy
If c.Controls.Count = 0 Then
Exit Sub
End If
Dim ctl As Control
For Each ctl In c.Controls
iterate(ctl)
Next
End Sub
End Class
 

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