Is there a method for searching for TreeNode.Text field in TreeView.Nodes collection?

Romz picture Romz · Sep 12, 2012 · Viewed 49.3k times · Source

Like this:

TreeNode[] treeNodes = treeView.Nodes.Find(searchString, true);

but I want it to search in the text field instead of the name field.

Answer

Habib picture Habib · Sep 12, 2012

I am not aware of any inbuilt method but you may use LINQ

TreeNode[] treeNodes = treeView.Nodes
                                    .Cast<TreeNode>()
                                    .Where(r => r.Text == "yourText")
                                    .ToArray();