Category / Section
How to highlight selected cells with border for each cell in WPF GridControl?
1 min read
You can highlight each selected cell with special border when it is selected using grid.Model.QueryCellInfo event and SelectionChanged event.
Refer the below code for your reference where selected cells border changed in QueryCellInfo event and previous selection get cleared by invalidating the entire grid in SelectionChanged event.
C#
grid.Model.SelectionChanged += Model_SelectionChanged; grid.Model.QueryCellInfo += Model_QueryCellInfo; private void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) { if (e.Cell.RowIndex > 0 && e.Cell.ColumnIndex > 0) { if (grid.Model.SelectedRanges.AnyRangeContains(GridRangeInfo.Cell(e.Cell.RowIndex, e.Cell.ColumnIndex))) { e.Style.Borders.All = new Pen(Brushes. DarkGreen, 2); } } } private void Model_SelectionChanged(object sender, GridSelectionChangedEventArgs e) { if(e.Reason==GridSelectionReason.MouseDown || e.Reason==GridSelectionReason.MouseUp) { grid.InvalidateCells(); } }
Sample: View sample in GitHub