Hello,
I am using WPF RadGridView in a common user control, and this control supports many different types of data. The grid is therefore built dynamically in code, and there is no XAML except to define the grid itself. The data is bound using the ItemsSource property to a QueryableCollectionView. Our client has requested that we provide a search on the visible grid elements (i.e. current page only), and they do NOT want to filter based on the search, only highlight the cells where the text was found.
I have implemented the code necessary to perform the search. However, at the point where I find a match, I need to highlight the cell containing the match. I know the row and column at this point, but I am unclear how to go about changing the cell style with only this information. Do you have any suggestions?
Here is the event code to perform the search after the search text box (txtSearch) is filled:
I am using WPF RadGridView in a common user control, and this control supports many different types of data. The grid is therefore built dynamically in code, and there is no XAML except to define the grid itself. The data is bound using the ItemsSource property to a QueryableCollectionView. Our client has requested that we provide a search on the visible grid elements (i.e. current page only), and they do NOT want to filter based on the search, only highlight the cells where the text was found.
I have implemented the code necessary to perform the search. However, at the point where I find a match, I need to highlight the cell containing the match. I know the row and column at this point, but I am unclear how to go about changing the cell style with only this information. Do you have any suggestions?
Here is the event code to perform the search after the search text box (txtSearch) is filled:
private void SearchTextBox_Search(object sender, RoutedEventArgs e){ int foundCellCount = 0; foreach (object o in ((QueryableCollectionView)theGrid.ItemsSource)) { if (o != null) { Type rowType = o.GetType(); PropertyInfo[] props = rowType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static); foreach (PropertyInfo pi in props) { if (IsVisibleColumn(pi.Name)) { object oCellVal = pi.GetValue(o, null); if ((oCellVal != null) && ((oCellVal.GetType() == typeof(int)) || (oCellVal.GetType() == typeof(string)) || (oCellVal.GetType() == typeof(long)))) { string cellVal = oCellVal.ToString(); if (cellVal.Contains(txtSearch.Text)) { // Match found foundCellCount++; // NEED TO HIGHLIGHT THE CONTAINING CELL HERE!!! } } } } } } if (foundCellCount > 0) { MessageBox.Show(string.Format("Match found in {0} cells", foundCellCount)); } else { MessageBox.Show("Not Found!"); }}