Category / Section
How to enable find and replace in WinForms GridGroupingControl?
1 min read
Find and replace
To implement
find and replace with keyboard shortcut in WinForms GridGroupingControl you
need to use the event TableControlCurrentCellKeyDown. The searching and
replacing of text and numbers can be done as like the Find and Replace
functionality in the Excel. This can be done by using dialog or
programmatically. This can be achieved to the GridGroupingControl by creating a
custom class GridFindReplaceDialog.
C#
// Displays the Find and Replace Dialog box.
void gridGroupingControl1_TableControlCurrentCellKeyDown(object sender, GridTableControlKeyEventArgs e)
{
if(e.Inner.Control)
{
if(e.Inner.KeyCode == Keys.F || e.Inner.KeyCode == Keys.H)
{
//if CTRL+F||CTRL+H is used, the findandreplacedialog will be displayed.
GridFindReplaceDialog f = new GridFindReplaceDialog(this.gridGroupingControl1, "Metro");
f.ShowDialog();
}
}
}
VB
'Displays the Find and Replace Dialog box.
Private Sub gridGroupingControl1_TableControlCurrentCellKeyDown(ByVal sender As Object, ByVal e As GridTableControlKeyEventArgs)
If e.Inner.Control Then
If e.Inner.KeyCode = Keys.F OrElse e.Inner.KeyCode = Keys.H Then
'if CTRL+F||CTRL+H is used, the findandreplacedialog will be displayed.
Dim f As New GridFindReplaceDialog(Me.gridGroupingControl1, "Metro")
f.ShowDialog()
End If
End If
End Sub
The screenshot below illustrates the enabling of the find and replace window.
Samples:
Reference Link: Find and Replace