How to perform incremental search in WinForms GridGroupingControl?
Find and replace
In order to perform the incremental search in WinForms GridGroupingControl, the GridFindReplaceDialogSink class can be used. The GridFindReplaceDialogSink class is used to perform Find and Replace in GridGroupingControl. The GridHighlightSearchText class can be used to highlight the search text of grid with default color(yellow). This feature can be added to the GridGroupingControl by including the Syncfusion.GridHelperClasses.Windows.dll to the assembly reference.
C#
//To highlight the text on searching GridHighlightSearchText highlighttext = new GridHighlightSearchText(); highlighttext.HighlightColor = colorPickerButton3.SelectedColor; //To wire the FindReplace dialog to grid GridFindReplaceDialogSink frDialog = new GridFindReplaceDialogSink(gridGroupingControl1.TableControl); //FindNext private void btnFindNext_Click(object sender, EventArgs e) { gridGroupingControl1.TableControl.Selections.Clear(); if (cmbSearch.Text != "") { AddToSearchedList(cmbSearch.Text); SetOptions(); locInfo = GridRangeInfo.Table(); clearHighlight(); frEvents = new GridFindReplaceEventArgs(cmbSearch.Text, "", options, locInfo); this.Find(frEvents); } this.gridGroupingControl1.TableControl.Refresh(); } //Replace private void btnReplace_Click(object sender, EventArgs e) { if (cmbSearch.Text != "" && cmbReplace.Text != "") { AddToSearchedList(cmbSearch.Text); SetOptions(); locInfo = GridRangeInfo.Table(); frEvents = new GridFindReplaceEventArgs(cmbSearch.Text, cmbReplace.Text, options, locInfo); frDialog.Replace(frEvents); } } //ReplaceAll private void btnReplaceAll_Click(object sender, EventArgs e) { if (cmbSearch.Text != "" && cmbReplace.Text != "") { AddToSearchedList(cmbSearch.Text); SetOptions(); locInfo = GridRangeInfo.Table(); frEvents = new GridFindReplaceEventArgs(cmbSearch.Text, cmbReplace.Text, options, locInfo); frDialog.ReplaceAll(frEvents); clearHighlight(); } else MessageBox.Show("Search/Replace value is missing"); }
VB
'To highlight the text on searching Dim highlighttext As New GridHighlightSearchText() highlighttext.HighlightColor = colorPickerButton3.SelectedColor 'To wire the FindReplace dialog to grid Dim frDialog As New GridFindReplaceDialogSink(gridGroupingControl1.TableControl) 'FindNext Private Sub btnFindNext_Click(ByVal sender As Object, ByVal e As EventArgs) gridGroupingControl1.TableControl.Selections.Clear() If cmbSearch.Text <> "" Then AddToSearchedList(cmbSearch.Text) SetOptions() locInfo = GridRangeInfo.Table() clearHighlight() frEvents = New GridFindReplaceEventArgs(cmbSearch.Text, "", options, locInfo) Me.Find(frEvents) End If Me.gridGroupingControl1.TableControl.Refresh() End Sub 'Replace Private Sub btnReplace_Click(ByVal sender As Object, ByVal e As EventArgs) If cmbSearch.Text <> "" AndAlso cmbReplace.Text <> "" Then AddToSearchedList(cmbSearch.Text) SetOptions() locInfo = GridRangeInfo.Table() frEvents = New GridFindReplaceEventArgs(cmbSearch.Text, cmbReplace.Text, options, locInfo) frDialog.Replace(frEvents) End If End Sub 'ReplaceAll Private Sub btnReplaceAll_Click(ByVal sender As Object, ByVal e As EventArgs) If cmbSearch.Text <> "" AndAlso cmbReplace.Text <> "" Then AddToSearchedList(cmbSearch.Text) SetOptions() locInfo = GridRangeInfo.Table() frEvents = New GridFindReplaceEventArgs(cmbSearch.Text, cmbReplace.Text, options, locInfo) frDialog.ReplaceAll(frEvents) clearHighlight() Else MessageBox.Show("Search/Replace value is missing") End If End Sub
The incremental search will be performed only when the grid has current cell and the GridGroupingControl does not have the current cell when loading. So, to search the contents, set the current cell as first cell by using below code,
C#
//To set the Current cell on loading itself this.gridGroupingControl1.TableControl.CurrentCell.MoveTo(this.gridGroupingControl1.TableControl.TopRowIndex , 1);
VB
'To set the Current cell on loading itself Me.gridGroupingControl1.TableControl.CurrentCell.MoveTo(Me.gridGroupingControl1.TableControl.TopRowIndex , 1)
Screenshot
Samples:
Reference link: https://help.syncfusion.com/windowsforms/gridgrouping/findandreplace
Conclusion
I hope you enjoyed learning about how to perform incremental search in WinForms GridGroupingControl.
You can refer to our WinForms Grid Grouping Control’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms Grid Grouping Control documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms Grid Control and other WinForms components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!