Skip to main content

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.

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