I'm new to the concept of recursion and it's quite confusing to me. I found an article here on MSDN that talks about how to iterate through the nodes in a treeview. I've able to get the code example to work in my project, but rather than have it display a message box for each treenode, I'd like it to take the text property of each treenode and add it to an array.
Here's the code that I got:
Code Snippet
-
Private Sub ManningFiltersTreeView_AfterCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles ManningFiltersTreeView.AfterCheck
-
-
RecurseTree(ManningFiltersTreeView)
-
-
End Sub
-
-
Private Sub BuildArray(ByVal n As TreeNode)
-
-
MessageBox.Show(n.Text)
-
Dim aNode As TreeNode
-
For Each aNode In n.Nodes
-
BuildArray(aNode)
-
Next
-
-
End Sub
-
-
' Call the procedure using the top nodes of the treeview.
-
-
Private Sub RecurseTree(ByVal aTreeView As TreeView)
-
-
Dim n As TreeNode
-
For Each n In aTreeView.Nodes
-
BuildArray(n)
-
Next
-
-
End Sub
-
So basically where it says MessageBox.Show(n.Text), can I have it instead add the value of n.text to an array and then pass that back to my ManningFiltersTreeView_Aftercheck procedure?