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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to search and select record in WinForms DataGrid (SfDataGrid)?

Platform: WinForms |
Control: SfDataGrid

Search and select record

You can search and select a record in SfDataGrid based on the searched text by using the TextChanged event of TextBox.

C#

private void textBox1_TextChanged(object sender, System.EventArgs e)
{
    this.sfDataGrid.SearchController.Search(this.textBox1.Text);
}
 
private void nextButton_Click(object sender, System.EventArgs e)
{
    this.sfDataGrid.SearchController.FindNext(this.textBox1.Text);
    SetSelectedItem();
}
 
private void previousButton_Click(object sender, System.EventArgs e)
{
    this.sfDataGrid.SearchController.FindPrevious(this.textBox1.Text);
    SetSelectedItem();
}
 
private void SetSelectedItem()
{
    var rowIndex = this.sfDataGrid.SearchController.CurrentRowColumnIndex.RowIndex;
    var recordIndex = this.sfDataGrid.TableControl.ResolveToRecordIndex(rowIndex);
    this.sfDataGrid.SelectedIndex = recordIndex;
}

VB

Private Sub textBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles textBox1.TextChanged
 Me.sfDataGrid.SearchController.Search(Me.textBox1.Text)
End Sub
 
Private Sub nextButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click
 Me.sfDataGrid.SearchController.FindNext(Me.textBox1.Text)
 SetSelectedItem()
End Sub
 
Private Sub previousButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button2.Click
 Me.sfDataGrid.SearchController.FindPrevious(Me.textBox1.Text)
 SetSelectedItem()
End Sub
 
Private Sub SetSelectedItem()
 Dim rowIndex = Me.sfDataGrid.SearchController.CurrentRowColumnIndex.RowIndex
 Dim recordIndex = Me.sfDataGrid.TableControl.ResolveToRecordIndex(rowIndex)
 Me.sfDataGrid.SelectedIndex = recordIndex
End Sub

 

Show the search and select the record in datagrid

Sample: How to search and select record in datagrid?

Reference link: https://help.syncfusion.com/windowsforms/datagrid/search

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