Skip to main content

How to Custom Paint Column Headers

The following example demonstrates how to handle the tree list’s OnCustomDrawHeaderCell event, used to manually paint column headers:

//...
procedure <Form>.<TreeList>CustomDrawHeaderCell(Sender: TObject; ACanvas: TcxCanvas; AViewInfo: TcxTreeListHeaderCellViewInfo;
  var ADone: Boolean);
begin
  // specify the default color and font settings
  cxApplyViewParams (ACanvas, AViewInfo.ViewParams);
  // changes the font style to bold
  AViewInfo.ViewParams.Font.Style := [fsBold];
  // specify the column header's background color
  ACanvas.Brush.Color := $FAE6E6;
  // paint the column header
  ACanvas.FillRect(AViewInfo.BoundsRect);
  // draw the column's caption
  ACanvas.DrawTexT(AViewInfo.Text, AViewInfo.TextBounds, 0, True);
  // draw a frame around the header
  ACanvas.FrameRect(AViewInfo.BoundsRect, clBlack, 1);
  with AViewInfo do
    if (SortOrder <> soNone) then
      // paint the sort glyph, if sorting is applied
      TcxTreeList(Sender).LookAndFeel.Painter.DrawSortingMark(ACanvas, SortMarkBounds, SortOrder = soAscending);
  // suppress the default painting
  ADone := True;
end;
See Also