用VirtualListView的方法来加载数据时,用CustomDrawItem的方法来隔行显示不同的颜色,在listview(行选)被遮挡后或者连续乱点时重绘时隔行颜色会出现混乱甚至全部只显示一种颜色。而在没有采用VirtualListView加载数据时则完全没有这种现象,烦请哪位大侠指点了

解决方案 »

  1.   

    给出你CustomDrawItem的原代码。
      

  2.   

    我测试了一下,没问题啊.
    procedure TForm1.ListView1DrawItem(Sender: TCustomListView;
      Item: TListItem; Rect: TRect; State: TOwnerDrawState);
    begin
      With Sender do begin
        if (Item.Index mod 2) = 0 then begin
          Canvas.Brush.Color := clWhite;
          Canvas.Rectangle(Rect);
          Canvas.Font.Color := clBlue;
          Canvas.TextOut(Rect.Left+2, Rect.Top, Item.Caption);
          Canvas.TextOut(Rect.Left+Column[0].Width, Rect.Top+1, Item.SubItems.Strings[0]);
        end else begin
          Canvas.Brush.Color := clgray;
          Canvas.Rectangle(Rect);
          Canvas.Font.Color := clred;
          Canvas.TextOut(Rect.Left+2, Rect.Top, Item.Caption);
          Canvas.TextOut(Rect.Left+Column[0].Width, Rect.Top+1, Item.SubItems.Strings[0]);
        end;
      end;
    end;