Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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:

Delphi
//...
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;