)
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 perform incremental search in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: November 15, 2017 |
Last Revised Date: December 23, 2019
Tags: search

Find and replace

In order to perform the incremental search in 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

Search the specific value

Samples:

C#: IncrementalSearch_CS

VB: IncrementalSearch_VB

Reference link: https://help.syncfusion.com/windowsforms/classic/gridgroupingcontrol/findandreplace

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