Saturday, March 24, 2012

loop through nodes in treeview in c#

Hi! I'd like to loo through nodes in treeview. Thanks!

use a recursive function like this:

private void ParseNode(TreeNode node) {//TODO: work for each node goes here for BFSforeach (TreeNode childin node.ChildNodes) ParseNode(child);//TODO: work goes here for DFS }

and you would call it like this

foreach(TreeNode rootNode in treeControl.Nodes)
ParseNode(rootNode);


foreach (TreeNode node in this.TreeView1)
{
// do stuff
}

TreeView1 is the treeview control on the ASPX page.


Hi

Have a read on this article

http://www.codeproject.com/useritems/DataTreeView.asp

Hope it helps


Good article. Thank you for the link.

1 comments:

Post a Comment