Skip to content

Commit e8fae4d

Browse files
authored
How to search TreeNodeAdv based on its tag value in WinForms TreeViewAdv
How to search TreeNodeAdv based on its tag value in WinForms TreeViewAdv?
1 parent 2ba884a commit e8fae4d

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

README.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,49 @@
11
# How to search tree node based on its tag value in winforms treeviewadv?
2-
This example explains how to search tree node based on its tag value in winforms treeviewadv.
2+
3+
## Search TreeNodeAdv based on its tag value
4+
5+
In **TreeViewAdv**, you can filter **TreeNodeAdv** based on its Tag value. The following code example demonstrates the same.
6+
7+
**C# Code Snippet:**
8+
9+
```C#
10+
List<TreeNodeAdv> nodes;
11+
//To search all nodes
12+
nodes = treeViewAdv1.SearchTree().Where(n => n.Tag == "Search node").ToList();
13+
public static class SOExtension
14+
{
15+
public static IEnumerable<TreeNodeAdv> SearchTree(this TreeViewAdv treeView)
16+
{
17+
return SearchTree(treeView.Nodes);
18+
}
19+
public static IEnumerable<TreeNodeAdv> SearchTree(this TreeNodeAdvCollection coll)
20+
{
21+
return coll.Cast<TreeNodeAdv>().Concat(coll.Cast<TreeNodeAdv>().SelectMany(x => SearchTree(x.Nodes)));
22+
}
23+
}
24+
25+
```
26+
27+
**VB Code Snippet:**
28+
29+
```VB
30+
Private nodes As List(Of TreeNodeAdv)
31+
'To search all nodes
32+
nodes = treeViewAdv1.FlattenTree().Where(Function(n) n.Tag = "Search node").ToList()
33+
Public Module SOExtension
34+
<System.Runtime.CompilerServices.Extension()> _
35+
Public Function SearchTree(ByVal treeView As TreeViewAdv) As IEnumerable(Of TreeNodeAdv)
36+
Return SearchTree(treeView.Nodes)
37+
End Function
38+
<System.Runtime.CompilerServices.Extension()> _
39+
Public Function SearchTree(ByVal coll As TreeNodeAdvCollection) As IEnumerable(Of TreeNodeAdv)
40+
Return coll.Cast(Of TreeNodeAdv)().Concat(coll.Cast(Of TreeNodeAdv)().SelectMany(Function(x) SearchTree(x.Nodes)))
41+
End Function
42+
End Module
43+
44+
```
45+
46+
The following screenshot illustrates the search TreeNodeAdv by using its Tag value.
47+
48+
![Search TreeNodeAdv by using its tag value](Searchbytagvalue.png)
49+

0 commit comments

Comments
 (0)