Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
# Row-and-column-header-highlighting-based-on-selection-in-WPF-Grid-Control
This sample shows row and column header highlighting based on selection in WPF Grid Control.
# How to Highlighting Row and Column Header Based on Selection in WPF GridControl?

This sample shows row and column header highlighting based on selection in [WPF GridControl](https://www.syncfusion.com/wpf-controls/excel-like-grid).

In Excel, whenever a selection is made, the headers of those rows and columns which are involved in the selection will be highlighted. You can get a similar behavior in the Grid by overriding the [OnPrepareRenderCell](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.Grid.GridControlBase.html#Syncfusion_Windows_Controls_Grid_GridControlBase_OnPrepareRenderCell_Syncfusion_Windows_Controls_Grid_GridPrepareRenderCellEventArgs_) method.

`OnPrepareRenderCell` method will be invoked for every cell in the grid, when they are about to be rendered. Hence, using this method, the cells which are going to be rendered are identified and their headers are highlighted.

``` csharp
class ExcelGrid : GridControl
{
protected override void OnPrepareRenderCell(GridPrepareRenderCellEventArgs e)
{
base.OnPrepareRenderCell(e);
if (e.Cell.RowIndex == 0 && Model.SelectedRanges.AnyRangeIntersects(GridRangeInfo.Col(e.Cell.ColumnIndex)))
{
e.Style.Background = this.excelOrange;
}
else if (e.Cell.ColumnIndex == 0 && Model.SelectedRanges.AnyRangeIntersects(GridRangeInfo.Row(e.Cell.RowIndex)))
{
e.Style.Background = this.excelOrange;
}
}
private Brush excelOrange = new SolidColorBrush(Color.FromRgb(244, 198, 111));
}
```

![GridControl with Highlighting row and column header](RowAndColumnHeaderHighlighted.png)
Binary file added RowAndColumnHeaderHighlighted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.