Iterate through All nodes in a Treeview control

M

Matt Hamilton

Sean said:
How to iterate nodes (including child nodes) in a Treeview using VB.Net?

Here's some C# code to do it. I don't think it's a huge leap to
translate it to VB.

private void DoStuffWithNodes(TreeNodeCollection nodes)
{
foreach (TreeNode node in nodes)
{
// Do stuff with "node"
/* ... */

// Now do the same stuff with the nodes beneath this node
DoStuffWithNodes(node.Nodes);
}
}

Then in your normal code (under a button click or something):

{
DoStuffWithNodes(treeView1.Nodes);
}

Hope this helps!
 
R

Robbe Morris [C# MVP]

TreeView FAQ. Code is in C# but easily translated to VB.NET

http://www.eggheadcafe.com/tutorials/aspnet/847ac120-3cdc-4249-8029-26c15de209d1/treeview-faq.aspx

--
Robbe Morris - 2004-2006 Microsoft MVP C#
I've mapped the database to .NET class properties and methods to
implement an multi-layered object oriented environment for your
data access layer. Thus, you should rarely ever have to type the words
SqlCommand, SqlDataAdapter, or SqlConnection again.
http://www.eggheadcafe.com/articles/adonet_source_code_generator.asp
 

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