背景项目列表视图 - Delphi

Background Item list view - Delphi

我想知道如何绘制项目列表视图。

我的情况如下: 我有一个列表视图,每次您进行检查并且此检查 returns 为真时,您都必须更改列表视图的线条颜色。我看到例子是换颜色的,但是我不能适应我想要的。

procedure TForm1.OncustomDrawItem(Sender: TCustomListView; Item: TListItem;
  State: TCustomDrawState; var DefaultDraw: Boolean);
begin
  if corlistview then Begin
         LstbxDados.Canvas.Brush.Color:= RGB(0, 0, 0);
         corlistview := false;
       End;
end;

程序

var corlistview : boolean = false;

procedure carrega(t:String);
begin
           if beginNada then begin
                  corlistview :=  true;
            end;

                LstbxDados.Items.BeginUpdate;
                try
                  countX := countX +1;
                with LstbxDados.Items.Add do begin
                  Caption := IntToStr(i+1);
                  Subitems.add(title);
                  Subitems.add(url);
                end;
                finally
                  LstbxDados.Items.EndUpdate;
                end;
end;

如何根据我的情况调整代码?

试试这个。我为 TListItem 字幕使用了随机奇数和偶数来模拟您样本中具有布尔结果的函数。

procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
  var i:integer;
begin
  i:= strtoint(Item.Caption);
  if i mod 2 =0 then
  begin
    Sender.Canvas.Brush.Color:=clNavy;
    Sender.Canvas.FillRect(Item.DisplayRect(TDisplayCode.drBounds));
  end;
end;