procedure TFrmMain.btn1Click(Sender: TObject);
var
 Lv1 : TlistView;
begin
  
   if (Lv1.Items[i].Caption = Lv2.Items[i].Caption) and
        (Lv1.Items[i].SubItems.strings[0] = Lv2.Items[i].SubItems.strings[0])  then
      begin
        //显示这一行(ListView这一行)的颜色为 红色;  
      end
end;

解决方案 »

  1.   

    在ListView的OnCustomDrawItem事件写控制代码
     
    if Items.Caption = '红色' then
     beign
       ListView.Canvas.Font.Color:= clRed;
     end;
      

  2.   

    在CustomDrawItem事件中自己绘制, 参考:procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
      Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
    var
      p:trect;
    begin
    if cdsselected in state then
    begin
      listview1.Canvas.Font.Color:=clgreen;
      listview1.Canvas.brush.Color:=clred;
      p:=item.displayrect(drselectbounds);
      listview1.Canvas.FillRect(p);
      listview1.Canvas.Textout(p.Left+2,p.Top,item.Caption);
      listview1.Canvas.brush.Color:=clblue;
      listview1.Canvas.FrameRect(item.displayrect(drselectbounds));
      defaultdraw:=false;
    end;
    end;
      

  3.   

    procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
      Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
    var
      R: TRect;
    begin
      with TListView(Sender).canvas do
       if cdsSelected in State then
        begin
          font.Style := [fsBold];
          font.color := clred;
          brush.Color := clgreen;
          R := item.DisplayRect(drlabel);
          textout(R.Left + 1, R.Top + 1, item.Caption);
          defaultdraw := False;
        end
        else
          DefaultDraw:=true;
    end;
      

  4.   

    我是想在下面过程控制啊procedure TFrmMain.btn1Click(Sender: TObject); 
      if (Lv1.Items[i].Caption = Lv2.Items[i].Caption) and 
            (Lv1.Items[i].SubItems.strings[0] = Lv2.Items[i].SubItems.strings[0])  then 
          begin 
            //显示这一行(ListView这一行)的颜色为 红色;  
            //如果满足以上条件,再绘制符合条件的这一行的颜色.
          end 
      

  5.   

    你可以在 按钮点击的时候給listview 选择的行设置一个状态值,然后在ListView1CustomDrawItem 里面判断这个状态值来绘制listview 。
      

  6.   


    procedure TFrmMain.btnClick(Sender: TObject);
    var
      rect: TRect;
      i,x:integer;
    begin
      if (Lv1.Items[i].Caption = Lv2.Items[i].Caption) and
            (Lv1.Items[i].SubItems.strings[0] = Lv2.Items[i].SubItems.strings[0])  then
      begin
        rect := Lv1.Items[0].DisplayRect(drBounds)  ;
        Lv1.Canvas.Font.Color := clWhite;
        Lv1.Canvas.Brush.Color:= clRed;
        Lv1.Canvas.FillRect(rect);
        Lv1.Canvas.Textout(rect.left,rect.top,Lv1.Items[0].caption);  //
        x:=0;
        for i:=0 to Lv1.Columns.Count-2   do
        begin
          x:=x+Lv1.Columns[i].Width;
          Lv1.Canvas.Textout(rect.Left+x,rect.Top, Lv1.Items[0].SubItems.Strings[i]);//显示SubItems文字
        end;
      end;
    end;