in a treeview, when I have searched all the current node's child nodes and when it finds an item it needs to find in the childnodes, how can i continue searching going back up one level and just carrying on?
Printable View
in a treeview, when I have searched all the current node's child nodes and when it finds an item it needs to find in the childnodes, how can i continue searching going back up one level and just carrying on?
If you're searching using recursion then you don't have to do anything because you will continue with the next node inherently, e.g.Just call that method and pass the Nodes property of your TreeView to the first argument and it will recursively search the entire tree, popping up a message each time it encounters a node whose Text matches the specified value.CSharp Code:
private void FindNodes(TreeNodeCollection nodes, string text) { foreach (TreeNode node in nodes) { if (node.Text == text) { MessageBox.Show(node.FullPath, "Match Found"); this.FindNodes(node.Nodes, text); } } }
dear jmcilhinney,
call FindNodes(Treeview1.nodes,"Server")
is this correct ?