How to apply highlight style for a selected cells within a CaptionSummaryRow on SfDataGrid
Hello,
I want to create a style that applies the same highlight style on that we have on selected cell on a SfDataGrid, but this time in a CaptionSummaryRow. Is there a way to create a style and apply this style when a cell is selected in the CaptionSummaryRow?
Best,
Eric
SIGN IN To post a reply.
1 Reply
SR
Senthilkumar Ranganathan
Syncfusion Team
January 27, 2026 11:59 AM UTC
Hi Eric Nguyen,
We have reviewed your query. Based on your requirement of highlighting the selected cells in the CaptionSummary can be achieved using a StyleSelector. Within the selector, you can retrieve the pressed GridCellInfo by using the GetGridCellInfo method by passing the PressedRowColumnIndex, then compare its MappingName with the CaptionSummaryCell to apply the appropriate style to the selected cell.
UG Link: CaptionSummaryCellStyle
Code Snippet for highlight the selected cells in the CaptionSummaryRow:
We have reviewed your query. Based on your requirement of highlighting the selected cells in the CaptionSummary can be achieved using a StyleSelector. Within the selector, you can retrieve the pressed GridCellInfo by using the GetGridCellInfo method by passing the PressedRowColumnIndex, then compare its MappingName with the CaptionSummaryCell to apply the appropriate style to the selected cell.
UG Link: CaptionSummaryCellStyle
Code Snippet for highlight the selected cells in the CaptionSummaryRow:
public class CaptionSummaryCellStyleSelector : StyleSelector { SfDataGrid dataGrid = (Application.Current.MainWindow as MainWindow).dataGrid; GridCellInfo cell = null; public override Style SelectStyle(object item, DependencyObject container) { if ((dataGrid.SelectionController as GridCellSelectionController) != null) { var pressedRowColumnIndex = (dataGrid.SelectionController as GridCellSelectionController).GetType().GetProperty("PressedRowColumnIndex", BindingFlags.Instance | BindingFlags.NonPublic).GetValue((dataGrid.SelectionController as GridCellSelectionController)); if (pressedRowColumnIndex != null) cell = dataGrid.GetGridCellInfo((RowColumnIndex)pressedRowColumnIndex); var nodeEntry = cell.GetType().GetProperty("NodeEntry", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(cell); if (nodeEntry != null && item == nodeEntry && (cell as GridCellInfo).Column.MappingName == (container as GridCaptionSummaryCell).ColumnBase.GridColumn.MappingName) return Application.Current.Resources["SelectedCaptionSummaryCellStyle"] as Style; } return base.SelectStyle(item, container); } } |
To update the style at runtime, we used the UpdateDataRow method to refresh the CaptionSummaryRow in the SelectionChanged event when the cell is selected.
Code Snippet for update the style at runtime:
private void DataGrid_SelectionChanged(object sender, GridSelectionChangedEventArgs e) { if (e.AddedItems != null) { foreach (var item in e.AddedItems) { GridCellInfo gridCellInfo = item as GridCellInfo; if (gridCellInfo == null) continue; var nodeEntry = gridCellInfo.GetType().GetProperty("NodeEntry", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(gridCellInfo); if (nodeEntry != null && nodeEntry is Group group) { var index = dataGrid.ResolveStartIndexOfGroup(group); this.dataGrid.UpdateDataRow(index); } } } if (e.RemovedItems != null) { foreach (var item in e.RemovedItems) { GridCellInfo gridCellInfo = item as GridCellInfo; if (gridCellInfo == null) continue; var nodeEntry = gridCellInfo.GetType().GetProperty("NodeEntry", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(gridCellInfo); if (nodeEntry != null && nodeEntry is Group group) { var index = dataGrid.ResolveStartIndexOfGroup(group); this.dataGrid.UpdateDataRow(index); } } } } |
Gif Illustration:
Please find the sample demo in the attachment.
Note: Multiple cell selection within the same CaptionSummaryRow is not feasible because the CaptionSummaryRow is treated internally as a single GridCellInfo. Therefore, when multiple selection is enabled, selecting one CaptionSummaryCell and then clicking another within the same row will clear the selection. So, it cannot be achieved.
Regards,
Senthilkumar Ranganathan.
Attachment: SfDataGrid_Demo4_8_77430d2f.zip
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
EN Eric Nguyen
- Jan 26, 2026 09:19 PM UTC
- Jan 27, 2026 11:59 AM UTC