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 Band Headers

The following example demonstrates how to handle the tree list’s OnCustomDrawBandHeaderCell event, used to manually paint band headers.

In the example, the leftmost visible band header is custom painted.

Delphi
//...
procedure <Form>.<TreeList>CustomDrawBandHeaderCell(Sender: TcxCustomTreeList; ACanvas: TcxCanvas; AViewInfo: TcxTreeListHeaderCellViewInfo; var ADone: Boolean);
begin
  // draw the first visible band header
  if not TcxTreeListBandHeaderCellViewInfo(AViewInfo).Band.IsLeftMost then
  begin
    // allow default painting
    ADone := False;
    Exit;
  end;
  // apply the current font and color settings
  cxApplyViewParams(ACanvas, AViewInfo.ViewParams);
  // paint the band header's background
  ACanvas.FillRect(AViewInfo.BoundsRect);
  // draw the band's caption text
  ACanvas.DrawTexT('CustomDrawBandHeader', AViewInfo.TextBounds, 0, True);
  // draw the band's borders
  ACanvas.FrameRect(AViewInfo.BoundsRect, clBlack);
  // suppress the default painting
  ADone := True;
end;