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

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