how to search a TreeNode?

  • Thread starter Thread starter Rob R. Ainscough
  • Start date Start date
R

Rob R. Ainscough

Looking for an efficient way to get a TreeNode out of my rootTreeNode -- for
example I know the FullPath -- is there a quick way to locate the node
matching my FullPath?

Rob.
 
public TreeNode GetNodeByPath(TreeNode rootNode, string strFullPath)
{
if(rootNode==null)
return null;
TreeNode hotNode = rootNode;
string[] nodes = strFullPath.Split('\\');
for(int i=1; i<nodes.Length; i++)
{
TreeNode node0 = null;
foreach(TreeNode node in hotNode.Nodes)
{
if(node.Text == nodes)
{
node0 = node;
break;
}
}
if(node0 == null)
break;
hotNode = node0;
}
return hotNode;
}
 

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

Similar Threads


Back
Top