Skip to main content

How to Custom Paint Band Backgrounds

The tree list’s OnCustomDrawBandCell event is used to paint the following band background areas: band header, band content (data cells), group footer, footer, band separator.

If you want to custom paint a particular area in a different manner, use the event’s ViewInfo.Part property to determine the area to paint. Available areas that are specified via the ViewInfo.Part property are represented by the TcxTreeListBandPart enumeration.

The following example is taken from the CustomDrawDemo that is shipped with the product. It demonstrates how to handle the tree list’s OnCustomDrawBandCell event, used to manually paint different areas of a band‘s background.

// Delphi

// …

uses

// …

CustomDrawDemoConsts;
procedure <Form>.<TreeList>CustomDrawBandHeader(Sender: TcxCustomTreeList; ACanvas: TcxCanvas; AViewInfo: TcxTreeListBandCellViewInfo; var ADone: Boolean);
const

// specify areas to draw

ADrawArea: array [tlbpHeader..tlbpFooter] of TCustomDrawArea = (cdaHeader, cdaCellsGroup, cdaGroupFooter, cdaFooter);
begin
  ADone := DrawItem(FCustomDrawInfo[ADrawArea[AViewInfo.Part]], ACanvas, AViewInfo.BoundsRect);
end;
function TCustomDrawDemoMainForm.DrawItem(AItem: TcxItemCustomDrawInfo; ACanvas: TcxCanvas; const R: TRect): Boolean;
begin
  case AItem.DrawingStyle of
    cdsBkImage:
       ACanvas.FillRect(R, AItem.Bitmap);
    cdsGradient:
       DrawGradient(ACanvas.Canvas, R,
        ColorScheme[Integer(AItem.ColorScheme), 1],
        ColorScheme[Integer(AItem.ColorScheme), 0], 40,
        Integer(AItem.ColorScheme) > 1);
  end;
  Result := (AItem.DrawingStyle <> cdsDefaultDrawing);
end;