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(); }