Articles in this section
Category / Section

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

1 min read

You can search and select a record in WPF DataGrid (SfDataGrid) based on the searched text by using the TextChanged event of TextBox like below,

private void searchTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
    text = (e.Source as TextBox).Text.ToLower();
    this.datagrid.SearchHelper.Search(text);
    datagrid.SearchHelper.FindNext(text);
    SetSelectedItem();
}
 
private void SetSelectedItem()
{
    var rowIndex = this.datagrid.SearchHelper.CurrentRowColumnIndex.RowIndex;
    var recordIndex = this.datagrid.ResolveToRecordIndex(rowIndex);
    this.datagrid.SelectedIndex = recordIndex;
}
 
private void Button_Click(object sender, RoutedEventArgs e)
{
    datagrid.SearchHelper.FindNext(text);
    SetSelectedItem();
}

 

Search and select the record in WPF DataGrid

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied