Articles in this section
Category / Section

How to highlight the row headers along with the cell selection?

You can highlight the row headers along with the cell selection by using the following two methods.

  1. InternalGrid_SelectionChanged(object sender, GridSelectionChangedEventArgs e)
  2. 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;
                    }
                }
           }
        }

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied