How to find and replace cell value in the WinForms GridControl?
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.
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();
}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 SubThe 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);
}
}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 SubThe following code examples are for ReplaceAll method.
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");
}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 SubThe following screenshot illustrates the Find and Replace behavior in the GridControl.

Samples:
C#: GridFindReplcae-C#.
VB: GridFindReplace-VB.
Reference Link: Find and Replace