CSharp Code:
private TreeNode FindNode(TreeNodeCollection nodes, string text)
{
TreeNode match = null;
foreach (TreeNode node in nodes)
{
if (node.Text.StartsWith(text))
{
// The current node is the first match.
match = node;
break;
}
else if ((match = this.FindNode(node.Nodes, text)) != null)
{
// A descendant of the current node is the first match.
break;
}
}
return match;
}
Just note that, while I wrote that code in an IDE I never actually tested it, so I can't guarantee it 100%. I'll leave the testing to you.