Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,54 @@
# How to filter the tree node based on the node ID in winforms treeviewadv?
This example explains how to filter the tree node based on the node ID in winforms treeviewadv.

## Filter the node based on NodeID

In the [TreeViewAdv](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Tools.TreeViewAdv.html), [TreeNodeAdv](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Tools.TreeNodeAdv.html) can be filtered based on its value by performing the iteration process. The following code example demonstrates the same.

**C# Code snippet:**

```C#

for(int nodeId = 0; nodeId <= 10000; nodeId++)
{
//Custom node for ID propety
CustomTreeNodeAdv customNode = new CustomTreeNodeAdv();
customNode.ID = nodeId;
customNode.Text = "Node" + nodeId.ToString();
this.treeViewAdv1.Nodes.Add(customNode);
}
//Iterates the nodes in the TreeViewAdv
foreach (CustomTreeNodeAdv item in this.treeViewAdv1.Nodes)
{
//Gets the TextBox value
string textvalue = item.ID.ToString();
if(this.integerTextBox1.Text == textvalue)
{
//Gets the node by its ID
MessageBox.Show(item.Text);
}
}

```

**VB Code snippet:**

```VB

For nodeId As Integer = 0 To 10000
'Custom node for ID propety
Dim customNode As New CustomTreeNodeAdv()
customNode.ID = nodeId
customNode.Text = "Node" & nodeId.ToString()
Me.treeViewAdv1.Nodes.Add(customNode)
Next nodeId
'Iterates the nodes in the TreeViewAdv
For Each item As CustomTreeNodeAdv In Me.treeViewAdv1.Nodes
'Gets the TextBox value
Dim textvalue As String = item.ID.ToString()
If Me.integerTextBox1.Text = textvalue Then
'Gets the node by its ID
MessageBox.Show(item.Text)
End If
Next item

```
29 changes: 29 additions & 0 deletions TreeViewAdvDemo/C#/CustomTreeNodeAdv.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Syncfusion.Windows.Forms.Tools;

namespace TreeViewAdvNodeId
{
//Creating custom class
public class CustomTreeNodeAdv : TreeNodeAdv
{
public CustomTreeNodeAdv()
{
//do something
}

private int m_NodeId;
/// <summary>
/// Gets/Sets the Id in TreeNodeAdv
/// </summary>
public int ID
{
get
{
return m_NodeId;
}
set
{
m_NodeId = value;
}
}
}
}
163 changes: 163 additions & 0 deletions TreeViewAdvDemo/C#/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions TreeViewAdvDemo/C#/Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Syncfusion.Windows.Forms;
using System;
using System.Windows.Forms;

namespace TreeViewAdvNodeId
{
public partial class Form1 : MetroForm
{
#region Constructor
public Form1()
{
InitializeComponent();
for (int nodeId = 0; nodeId <= 10000; nodeId++)
{
//Custom node for ID propety
CustomTreeNodeAdv customNode = new CustomTreeNodeAdv();
customNode.ID = nodeId;
customNode.Text = "Node" + nodeId.ToString();
this.treeViewAdv1.Nodes.Add(customNode);
}
this.buttonAdv1.Click += buttonAdv1_Click;
}
#endregion

void buttonAdv1_Click(object sender, EventArgs e)
{
//Iterating the nodes in the TreeViewAdv
foreach (CustomTreeNodeAdv item in this.treeViewAdv1.Nodes)
{
//To get the TextBox value
string textvalue = item.ID.ToString();
if (this.integerTextBox1.Text == textvalue)
{
//Get the node by its ID
MessageBox.Show(item.Text);
}
}
}
}
}
Loading