Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Like this:

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

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

like image 534
Romz Avatar asked Sep 12 '12 12:09

Romz


People also ask

How do you find a node in TreeView?

Use the FindNode method to get a node from the TreeView control at the specified value path. The value path contains a delimiter-separated list of node values that form a path from the root node to the current node. Each node stores its value path in the ValuePath property.

What is TreeNode C#?

The TreeNode label is set by setting the Text property explicitly. The alternative is to create the tree node using one of the TreeNode constructors that has a string parameter that represents the Text property. The label is displayed next to the TreeNode image, if one is displayed.


1 Answers

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(); 
like image 59
Habib Avatar answered Sep 21 '22 18:09

Habib