11# How to search and retrieve the tree node based on its text in WinForms TreeViewAdv?
22
3- ## Search and retrieve the TreeNodeAdv text
3+ In [ WinForms TreeViewAdv ] ( https://www.syncfusion.com/winforms-ui-controls/treeview ) has built-in support to search the ** TreeNodeAdv** based on its text, by using the class named ** TreeViewAdvFindReplaceDialog ** . It can be done using the following categories:
44
5- ** TreeViewAdv** has built-in support to search the ** TreeNodeAdv** based on its text, by using the class named ** TreeViewAdvFindReplaceDialog** . It can be done using the following categories:
651 . TreeViewSearchOption
762 . TreeViewSearchRange
873 . TreeViewSearchNavigation
98
109## TreeViewSearchOption
1110This property specifies the Searching option in TreeViewAdv.
11+
12121 . MatchWholeText
13132 . MatchCase
1414
@@ -78,13 +78,14 @@ This option helps to specify whether the search needs to be performed from the t
7878
7979This option helps to specify whether the search can be performed in the above cases repeatedly. The following code example demonstrates the same.
8080
81- ** C# Code snippet :**
81+ ** C#:**
8282
8383``` C#
8484// Initialize the TreeViewSearchForm
8585TreeViewSearchForm form ;
8686// To assign the TreeViewAdv to TreeViewSearchForm
8787form = new TreeViewSearchForm (this .treeViewAdv1 );
88+
8889// To show the search dialog
8990void treeViewAdv1_PreviewKeyDown (object sender , PreviewKeyDownEventArgs e )
9091{
@@ -101,46 +102,54 @@ public partial class TreeViewSearchForm : MetroForm
101102 TreeViewAdvFindReplaceDialog dialog = null ;
102103 // Initialize the TreeViewAdv
103104 private TreeViewAdv TreeView ;
104- // To pass the TreeviewAdv argument to the form.
105+
106+ // To pass the TreeviewAdv argument to the form.
105107 public TreeViewSearchForm (TreeViewAdv tree )
106108 {
107109 InitializeComponent ();
108110 TreeView = tree ;
109111 // To assign the TreeViewAdv to TreeViewSearchForm
110112 dialog = new TreeViewAdvFindReplaceDialog (this .TreeView );
111113 }
114+
112115 // To get the TreeViewSearchNavigation
113116 void comboBox3_SelectedIndexChanged (object sender , EventArgs e )
114117 {
115118 dialog .TreeViewSearchNavigation = (TreeViewSearchNavigation )this .SearchRangeCombo .Items [this .comboBox3 .Items .IndexOf (this .comboBox3 .SelectedItem )];
116119 }
120+
117121 // To get the TreeViewSearchRange
118122 private void SearchRangeCombo_SelectedIndexChanged (object sender , EventArgs e )
119123 {
120124 dialog .TreeViewSearchRange = (TreeViewSearchRange )this .SearchRangeCombo .Items [this .SearchRangeCombo .Items .IndexOf (this .SearchRangeCombo .SelectedItem )];
121125 }
126+
122127 // To get the TreeViewSearchOption
123128 private void SearchOptionCombo_SelectedIndexChanged (object sender , EventArgs e )
124129 {
125130 dialog .TreeViewSearchOption = (TreeViewSearchOption )this .SearchOptionCombo .Items [this .SearchOptionCombo .Items .IndexOf (this .SearchOptionCombo .SelectedItem )];
126131 }
132+
127133 // To Find TreeNodeAdv
128134 private void button1_Click (object sender , EventArgs e )
129135 {
130136 dialog .Find (this .findTextBox .Text );
131137 }
138+
132139 // To Find All the TreeNodeAdv
133140 private void button2_Click (object sender , EventArgs e )
134141 {
135142 dialog .FindAll (this .findTextBox .Text );
136143 }
144+
137145 // To Replace the TreeNodeAdv
138146 private void button3_Click (object sender , EventArgs e )
139147 {
140148 this .TreeView .SelectedNodes .Clear ();
141149 if (dialog .Find (this .findTextBox .Text ))
142150 dialog .Replace (this .replaceTextbox .Text );
143151 }
152+
144153 // To Replace All the TreeNodeAdv
145154 private void button4_Click (object sender , EventArgs e )
146155 {
@@ -152,14 +161,15 @@ public partial class TreeViewSearchForm : MetroForm
152161
153162```
154163
155- ** VB Code snippet :**
164+ ** VB.Net :**
156165
157166``` VB
158167
159168'Initialize the TreeViewSearchForm
160169Private form As TreeViewSearchForm
161170'To assign the TreeViewAdv to TreeViewSearchForm
162171form = New TreeViewSearchForm( Me .treeViewAdv1)
172+
163173'To show the search dialog
164174Private Sub treeViewAdv1_PreviewKeyDown( ByVal sender As Object , ByVal e As PreviewKeyDownEventArgs)
165175 If e.Modifiers = Keys.Control AndAlso e.KeyValue = Keys.F Then
@@ -174,40 +184,48 @@ Partial Public Class TreeViewSearchForm
174184 Private dialog As TreeViewAdvFindReplaceDialog = Nothing
175185 'Initialize the TreeViewAdv
176186 Private TreeView As TreeViewAdv
187+
177188 'To pass the TreeviewAdv argument to the form.
178189 Public Sub New ( ByVal tree As TreeViewAdv)
179190 InitializeComponent()
180191 TreeView = tree
181192 'To assign the TreeViewAdv to TreeViewSearchForm
182193 dialog = New TreeViewAdvFindReplaceDialog( Me .TreeView)
183194 End Sub
195+
184196 'To get the TreeViewSearchNavigation
185197 Private Sub comboBox3_SelectedIndexChanged( ByVal sender As Object , ByVal e As EventArgs)
186198 dialog.TreeViewSearchNavigation = CType ( Me .SearchRangeCombo.Items( Me .comboBox3.Items.IndexOf( Me .comboBox3.SelectedItem)), TreeViewSearchNavigation)
187199 End Sub
200+
188201 'To get the TreeViewSearchRange
189202 Private Sub SearchRangeCombo_SelectedIndexChanged( ByVal sender As Object , ByVal e As EventArgs) Handles SearchRangeCombo.SelectedIndexChanged
190203 dialog.TreeViewSearchRange = CType ( Me .SearchRangeCombo.Items( Me .SearchRangeCombo.Items.IndexOf( Me .SearchRangeCombo.SelectedItem)), TreeViewSearchRange)
191204 End Sub
205+
192206 'To get the TreeViewSearchOption
193207 Private Sub SearchOptionCombo_SelectedIndexChanged( ByVal sender As Object , ByVal e As EventArgs) Handles SearchOptionCombo.SelectedIndexChanged
194208 dialog.TreeViewSearchOption = CType ( Me .SearchOptionCombo.Items( Me .SearchOptionCombo.Items.IndexOf( Me .SearchOptionCombo.SelectedItem)), TreeViewSearchOption)
195209 End Sub
210+
196211 'To Find TreeNodeAdv
197212 Private Sub button1_Click( ByVal sender As Object , ByVal e As EventArgs) Handles button1.Click
198213 dialog.Find( Me .findTextBox.Text)
199214 End Sub
215+
200216 'To Find All the TreeNodeAdv
201217 Private Sub button2_Click( ByVal sender As Object , ByVal e As EventArgs) Handles button2.Click
202218 dialog.FindAll( Me .findTextBox.Text)
203219 End Sub
220+
204221 'To Replace the TreeNodeAdv
205222 Private Sub button3_Click( ByVal sender As Object , ByVal e As EventArgs) Handles button3.Click
206223 Me .TreeView.SelectedNodes.Clear()
207224 If dialog.Find( Me .findTextBox.Text) Then
208225 dialog.Replace( Me .replaceTextbox.Text)
209226 End If
210227 End Sub
228+
211229 'To Replace All the TreeNodeAdv
212230 Private Sub button4_Click( ByVal sender As Object , ByVal e As EventArgs) Handles button4.Click
213231 Me .TreeView.SelectedNodes.Clear()
0 commit comments