Recursively Traverse the Nodes of a TreeView Control

Category:
Forms and Controls
Type:
Snippets
Difficulty:
Intermediate
Author:
David Nishimoto

Version Compatibility: Visual Basic 6, Visual Basic 5

More information:
This snippet shows you how to loop through all the nodes of a tree view control with one function, which is called recursively. The sample just prints the text of each node to the immediate window, but obviously you can change it to do something more relevant to your needs. To use this example, add a TreeView Control to your form and copy and paste this code into the form's code window.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: