)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to search TreeNodeAdv based on its tag value in WinForms TreeViewAdv?

Platform: WinForms |
Control: TreeViewAdv |
Published Date: May 13, 2015 |
Last Revised Date: February 5, 2020

Search TreeNodeAdv based on its tag value

In TreeViewAdv, you can filter TreeNodeAdv based on its Tag value. The following code example demonstrates the same.

C#

List<TreeNodeAdv> nodes;
//To search all nodes
nodes = treeViewAdv1.SearchTree().Where(n => n.Tag == "Search node").ToList();
public static class SOExtension
{
    public static IEnumerable<TreeNodeAdv> SearchTree(this TreeViewAdv treeView)
    {
        return SearchTree(treeView.Nodes);
    }
    public static IEnumerable<TreeNodeAdv> SearchTree(this TreeNodeAdvCollection coll)
    {
        return coll.Cast<TreeNodeAdv>().Concat(coll.Cast<TreeNodeAdv>().SelectMany(x => SearchTree(x.Nodes)));
    }
}

VB

Private nodes As List(Of TreeNodeAdv)
'To search all nodes
nodes = treeViewAdv1.FlattenTree().Where(Function(n) n.Tag = "Search node").ToList()
Public Module SOExtension
    <System.Runtime.CompilerServices.Extension()> _
    Public Function SearchTree(ByVal treeView As TreeViewAdv) As IEnumerable(Of TreeNodeAdv)
        Return SearchTree(treeView.Nodes)
    End Function
    <System.Runtime.CompilerServices.Extension()> _
    Public Function SearchTree(ByVal coll As TreeNodeAdvCollection) As IEnumerable(Of TreeNodeAdv)
        Return coll.Cast(Of TreeNodeAdv)().Concat(coll.Cast(Of TreeNodeAdv)().SelectMany(Function(x) SearchTree(x.Nodes)))
    End Function
End Module

The following screenshot illustrates the output.

Search TreeNodeAdv by using its tag value

Figure 1: Search TreeNodeAdv by using its Tag value

Samples:

C#: http://www.syncfusion.com/downloads/support/directtrac/135929/TreeViewAdv_Search_Node1039237941.zip

VB: http://www.syncfusion.com/downloads/support/directtrac/137372/TreeViewAdv_Search_Node_VB1768653127.zip

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon