Skip to main content

How to Custom Paint Node Indicators

The following example demonstrates how to handle the tree list’s OnCustomDrawIndicatorCell event, used to manually paint node indicators.

In the example, a focus glyph for the focused node is painted manually as well as indicator cells.

//...
procedure <Form>.<TreeList>CustomDrawIndicatorCell(Sender: TcxCustomTreeList; ACanvas: TcxCanvas; AViewInfo: TcxTreeListIndicatorCellViewInfo; var ADone: Boolean);
var
  IndicatorKind: TcxIndicatorKind;
  // paint the indicator image (arrow)
  procedure InternalDrawIndicatorImage(ACanvas: TcxCanvas;
    const R: TRect; AKind: TcxIndicatorKind);
  var
    X, Y: Integer;
  begin
    if AKind = ikNone then Exit;
    with cxIndicatorImages, R do
    begin
      X := (Left + Right - Width) div 2;
      Y := (Top + Bottom - Height) div 2;
    end;
    // draw built-in indicator images
    cxIndicatorImages.Draw(ACanvas.Canvas, X, Y, Ord(AKind) - 1);
  end;
begin
  // specify the background color
  ACanvas.Brush.Color := $FAE6E6;
  // paint the background
  ACanvas.FillRect(AViewInfo.BoundsRect);
  if (AViewInfo.Node <> nil) and (AViewInfo.Node.Focused) then
    // the corresponding node is focused
    IndicatorKind := ikArrow
  else
    // the corresponding node is not focused
    IndicatorKind := ikNone;
  InternalDrawIndicatorImage(ACanvas, AViewInfo.BoundsRect, IndicatorKind);
  // draw a frame around the indicator cell
  ACanvas.FrameRect(AViewInfo.BoundsRect, clBlack, 1);
  // suppress the default painting
  ADone := True;
end;