Search code examples
delphilistviewcolorsrowpaint

Delphi: Paint Rows of ListView


I have a ListView (vsReport): the last SubItem has a text "wait". Then I will change it to "ok" or "error". How to paint a whole row (if to use Sender.Canvas.Brush.Color in CustomDrawItem it will be gaps between columns in Windows 7) with this SubItem in green (ok) and red (error)?

Thanks!


Solution

  • You can do

    procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
      Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
    begin
      if Item.Index = Sender.Items.Count - 1 then
      begin
        Sender.Canvas.Brush.Color := clSkyBlue;
        Sender.Canvas.FillRect(Item.DisplayRect(drBounds));
      end;
    end;
    

    but I advice against it, because it is buggy (and I don't know how to fix it).

    Screenshot