delphivcldelphi-10.4-sydney

Delphi - How can I change a single item Backgroundcolor in a TControlList


I try to get that white/grey pattern with the TControlList but was not able to find the right Property. ItemColor changes the backgroundcolor of every Item and Color itself changes Background for the complet control.

I had tried to manipulate the aCanvas object inside the OnBeforeDrawItem Event but that doesn't work either. Inside the documentation is loud silence.

Can anyone help with that?


Solution

  • You don't have to use canvas only set itemcolor

    procedure TForm1.ControlList1BeforeDrawItem(AIndex: Integer; ACanvas: TCanvas;
      ARect: TRect; AState: TOwnerDrawState);
    begin
    if Odd(aIndex)
      then ControlList1.ItemColor:=clWhite
      else ControlList1.ItemColor:=clLtGray;
    end;
    

    alternate rows for TControlList