Skip to main content

How to Custom Paint Previews

The following example demonstrates how to handle the tree list’s OnCustomDrawPreviewCell event, used to manually paint previews.

In the example, the focused node’s preview is painted differently than other previews.

//...
procedure <Form>.<TreeList>CustomDrawPreviewCell(Sender: TcxCustomTreeList; ACanvas: TcxCanvas; AViewInfo: TcxTreeListEditCellViewInfo; var ADone: Boolean);
begin
  if (AViewInfo.Node.Focused) then
    begin
      ACanvas.Brush.Color := $FAE6E6;
      ACanvas.Font.Style := [fsBold, fsItalic];
    end
  else
    begin
    ACanvas.Brush.Color := $AAE8EE;
    ACanvas.Font.Style := ACanvas.Font.Style - [fsBold];
    end;
  // paint the preview section's background
  ACanvas.FillRect(AViewInfo.BoundsRect);
  // change the font style to italic
  ACanvas.Font.Style := [fsItalic];
  // draw the preview section's contents
  ACanvas.DrawTexT(AViewInfo.DisplayValue, AViewInfo.VisibleRect, 0, True);
  // suppress the default painting
  ADone := True;
end;
See Also