)
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 find and replace cell value in the WinForms GridControl?

Platform: WinForms |
Control: GridControl |
Published Date: April 30, 2011 |
Last Revised Date: December 20, 2019
Tags: findreplace

Find and replace

To find a particular cell text, you can use the Find method of the GridFindReplaceDialogSink class. This class provides a default implementation of the IGridFindReplaceDialogSink. It also includes the Replace and ReplaceAll methods to replace the specified string with the given string. These methods accept the GridFindReplaceDialogSink class members that include properties like the string to be searched, the string to be replaced and the options for search criteria.

The following code examples are for Find method.

C#

private void button1_Click(object sender, EventArgs e)
{
   gridControl1.Selections.Clear();
   if (this.textBox1.Text != "")
   {
     options = GridFindTextOptions.WholeTable;
     locInfo = GridRangeInfo.Table();
     frEvents = new GridFindReplaceEventArgs(textBox1.Text, "", options, locInfo);
     //To find the given text
     frDialog.Find(frEvents);
   }
   this.gridControl1.Refresh();
}

 

VB

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
   gridControl1.Selections.Clear()
   If Me.textBox1.Text <> "" Then
     options = GridFindTextOptions.WholeTable
     locInfo = GridRangeInfo.Table()
     frEvents = New GridFindReplaceEventArgs(textBox1.Text, "", options, locInfo) 'find the text given 
     frDialog.Find(frEvents)
   End If
   Me.gridControl1.Refresh()
End Sub

The following code examples are for Replace method.

C#

private void button2_Click(object sender, EventArgs e)
{
  if (textBox1.Text != "" && textBox2.Text != "")
  {
     options = GridFindTextOptions.WholeTable;
     locInfo = GridRangeInfo.Table();
     frEvents = new GridFindReplaceEventArgs(textBox1.Text, textBox2.Text, options, locInfo);
     //To Replace the given texts
     frDialog.Replace(frEvents);
   }
}

 

VB

Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button2.Click
   If textBox1.Text <> "" AndAlso textBox2.Text <> "" Then
      options = GridFindTextOptions.WholeTable
      locInfo = GridRangeInfo.Table()
      frEvents = New GridFindReplaceEventArgs(textBox1.Text, textBox2.Text, options, locInfo)
      'To Replace the given the texts
 frDialog.Replace(frEvents)
   End If
End Sub

The following code examples are for ReplaceAll method.

 C#

private void button4_Click(object sender, EventArgs e)
{
    if (this.textBox1.Text != "" && this.textBox2.Text != "")
    {
       options = GridFindTextOptions.WholeTable;
       locInfo = GridRangeInfo.Table();
       //To Replace all the positions located in given text
       frEvents = new GridFindReplaceEventArgs(textBox1.Text, textBox2.Text, options, locInfo);
       frDialog.ReplaceAll(frEvents);
    }
       else
       MessageBox.Show("Search/Replace value is missing");
}

 

VB

Private Sub button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button4.Click
    If Me.textBox1.Text <> "" AndAlso Me.textBox2.Text <> "" Then
 options = GridFindTextOptions.WholeTable
       locInfo = GridRangeInfo.Table()
       'To replace all the positions located in given text
 frEvents = New GridFindReplaceEventArgs(textBox1.Text, textBox2.Text, options, locInfo)
 frDialog.ReplaceAll(frEvents)
    Else
 MessageBox.Show("Search/Replace value is missing")
    End If
End Sub

The following screenshot illustrates the Find and Replace behavior in the GridControl.

Find and replace the value in grid

Samples:

C#: GridFindReplcae-C#.

VB: GridFindReplace-VB.

Reference link: https://help.syncfusion.com/windowsforms/grid-control/find-and-replace

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