|
1 | | -# How-to-filter-the-node-based-on-the-node-ID-in-winforms-treeviewadv |
2 | | -This session describes how to filter the node based on the nodeID in winforms treeviewadv. |
| 1 | +# How to Filter the Node Based on the NodeID in WinForms TreeView? |
| 2 | + |
| 3 | +This sample describes how to filter the node based on the nodeID in [WinForms TreeView](https://www.syncfusion.com/winforms-ui-controls/treeview) (TreeViewAdv). |
| 4 | + |
| 5 | +In the `TreeViewAdv`, TreeNodeAdv can be filtered based on its value by performing the iteration process. The following code example demonstrates the same. |
| 6 | + |
| 7 | +#### C# |
| 8 | + |
| 9 | +``` csharp |
| 10 | +for(int nodeId = 0; nodeId <= 10000; nodeId++) |
| 11 | +{ |
| 12 | + //Custom node for ID propety |
| 13 | + CustomTreeNodeAdv customNode = new CustomTreeNodeAdv(); |
| 14 | + customNode.ID = nodeId; |
| 15 | + customNode.Text = "Node" + nodeId.ToString(); |
| 16 | + this.treeViewAdv1.Nodes.Add(customNode); |
| 17 | +} |
| 18 | +//Iterates the nodes in the TreeViewAdv |
| 19 | +foreach (CustomTreeNodeAdv item in this.treeViewAdv1.Nodes) |
| 20 | +{ |
| 21 | + //Gets the TextBox value |
| 22 | + string textvalue = item.ID.ToString(); |
| 23 | + if(this.integerTextBox1.Text == textvalue) |
| 24 | + { |
| 25 | + //Gets the node by its ID |
| 26 | + MessageBox.Show(item.Text); |
| 27 | + } |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +#### Vb |
| 32 | + |
| 33 | +``` vb |
| 34 | +For nodeId As Integer = 0 To 10000 |
| 35 | + 'Custom node for ID propety |
| 36 | + Dim customNode As New CustomTreeNodeAdv() |
| 37 | + customNode.ID = nodeId |
| 38 | + customNode.Text = "Node" & nodeId.ToString() |
| 39 | + Me.treeViewAdv1.Nodes.Add(customNode) |
| 40 | +Next nodeId |
| 41 | +'Iterates the nodes in the TreeViewAdv |
| 42 | +For Each item As CustomTreeNodeAdv In Me.treeViewAdv1.Nodes |
| 43 | + 'Gets the TextBox value |
| 44 | + Dim textvalue As String = item.ID.ToString() |
| 45 | + If Me.integerTextBox1.Text = textvalue Then |
| 46 | + 'Gets the node by its ID |
| 47 | + MessageBox.Show(item.Text) |
| 48 | + End If |
| 49 | +Next item |
| 50 | +``` |
0 commit comments