Iterate through child treenodes
-
I'm struggling to work out how to iterate through treenodes. What I've done is programmatically created a TreeView, creating a (DatabaseName) header as follows:
trvDbNameNormal = Me.TreeView1.Nodes.Add("DatabaseName", "Common tables: " & Me.cmbDatabases.Text.ToUpper, 0, 0)
The children (table names) within this node are created by:nodeTable = trvDbNameNormal.Nodes.Add(strTable, strTable, 1, 1)
What I want to do is iterate through these children to perform some SQL on the table names - but I can't figure out how to get the contents of these nodes. -
I'm struggling to work out how to iterate through treenodes. What I've done is programmatically created a TreeView, creating a (DatabaseName) header as follows:
trvDbNameNormal = Me.TreeView1.Nodes.Add("DatabaseName", "Common tables: " & Me.cmbDatabases.Text.ToUpper, 0, 0)
The children (table names) within this node are created by:nodeTable = trvDbNameNormal.Nodes.Add(strTable, strTable, 1, 1)
What I want to do is iterate through these children to perform some SQL on the table names - but I can't figure out how to get the contents of these nodes.The TreeNodesCollection class has an indexer so you can access each Node by trvDbNameNormal(0) or trvDbNameNormal(strTable) . The TreeNode class has a Text property which will return strTable name in the case of your code. Then simply write a recursive algorithm to walk the tree. something like:
Private Sub walkTree(t as TreeNode)
For i as Integer = 0 To T.Nodes.Count -1
' Do something usefull here
walkTree(T.Nodes(i))
Next
End Sub
I'm largely language agnostic
After a while they all bug me :doh: