Category / Section
How to highlight the row headers along with the cell selection?
1 min read
You can highlight the row headers along with the cell selection by using the following two methods.
- InternalGrid_SelectionChanged(object sender, GridSelectionChangedEventArgs e)
- InternalGrid_PrepareRenderCell(object sender, GridPrepareRenderCellEventArgs e)
By calling the SelectionChanged() method, it invalidates the corresponding header cells of selected cells.
C#
void InternalGrid_SelectionChanged(object sender, GridSelectionChangedEventArgs e)
{
_point = Mouse.GetPosition(_grid.InternalGrid);
_colIndex = _grid.InternalGrid.PointToCellRowColumnIndex(_point);
if (e.Reason == GridSelectionReason.MouseDown || e.Reason == GridSelectionReason.SetCurrentCell || e.Reason == GridSelectionReason.MouseMove || e.Reason == GridSelectionReason.SelectRange || e.Reason == GridSelectionReason.MouseUp)
{
if (_colIndex.ColumnIndex >= _grid.PivotRows.Count - 1)
{
grid.InternalGrid.InvalidateCell(GridRangeInfo.Row(_grid.PivotRows.Count - 1));
_grid.InternalGrid.InvalidateCell(GridRangeInfo.Col(_grid.PivotRows.Count - 1));
}
else
{
for (int i = _colIndex.ColumnIndex; i < _grid.PivotRows.Count; i++)
{
_grid.InternalGrid.InvalidateCell(GridRangeInfo.Row(i));
_grid.InternalGrid.InvalidateCell(GridRangeInfo.Col(i));
}
}
}
}
By calling the PrepareRenderCell() method, it highlights the row header cells along with the selected cells with customized styles.
C#
void InternalGrid_PrepareRenderCell(object sender, GridPrepareRenderCellEventArgs e)
{
_point = Mouse.GetPosition(_grid.InternalGrid);
_colIndex = _grid.InternalGrid.PointToCellRowColumnIndex(_point);
if (_colIndex.ColumnIndex >= _grid.PivotRows.Count - 1)
{
if (e.Cell.ColumnIndex == _grid.PivotRows.Count - 1 && _grid.InternalGrid.Model.SelectedRanges.AnyRangeIntersects(GridRangeInfo.Row(e.Cell.RowIndex)))
{
e.Style.Background = Brushes.Blue;
e.Handled = true;
}
}
else
{
for (int i = _colIndex.ColumnIndex; i < _grid.PivotRows.Count; i++)
{
if (e.Cell.ColumnIndex == i && _grid.InternalGrid.Model.SelectedRanges.AnyRangeIntersects(GridRangeInfo.Row(e.Cell.RowIndex)))
{
e.Style.Background = Brushes.Blue;
e.Handled = true;
}
}
}
}