Skip to main content

Painting Row Headers

  • 2 minutes to read

The ExpressVerticalGrid control provides several events allowing custom painting of the control’s elements (see the Custom Painting Overview topic for more information). The OnDrawRowHeader event occurs before painting the vertical grid’s row headers. Its parameters are listed below:

Parameter Description
`ACanvas Specifies the surface of the row header being painted. This parameter provides access to various painting methods.
`APainter Represents the painter object used for default painting. You can use the interface provided by the object to paint the header using the current style settings.
AHeaderViewInfo Specifies the ViewInfo object providing view information about the row header being painted. To obtain detailed information that depends on the row type, a type cast must be performed. For instance, if the current row is a category row, this parameter must be converted to the TcxCategoryRowHeaderInfo type.
Done Specifies whether the default painting routines should be suppressed. Set the parameter to True, to cancel default painting; set it to False to allow default painting. In the latter case, the changes you make are discarded.

The following OnDrawRowHeader event handler paints the parent rows’ expand buttons in white or yellow color depending on the row’s expanded state:

procedure TStylesSimpleDemoMainForm.cxDBVerticalGridDrawRowHeader(
  Sender: TObject; ACanvas: TcxCanvas; APainter: TcxvgPainter;
  AHeaderViewInfo: TcxCustomRowHeaderInfo; var Done: Boolean);
var
  AColor: TColor;
begin
  with AHeaderViewInfo do
  begin
    if Row.Expanded then
      AColor := clWhite
    else
      AColor := clYellow;
    APainter.Painter.DrawExpandButton(ACanvas, ButtonRect, Row.Expanded, AColor);
  end;
end;

The following image shows the code’s result: