listview用Report方式
如何让每次增加一行的时候是用不同的颜色显示,包括
字体颜色,背景颜色等等
谢谢帮忙

解决方案 »

  1.   

    在ListView的OnCustomDrawItem事件里——procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
      Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
    var
      R: TRect;
    begin
      with Sender.Canvas do begin
        R := Item.DisplayRect(drBounds);
        if Item.Index mod 2 = 1 then begin//对奇数行改变底色和字体
          Brush.Color := clTeal;
          Font.Color := clYellow;
          Font.Style := Font.Style + [fsBold];
          DefaultDraw := False;
        end;
        if cdsSelected in State then begin
          Brush.Color := clHighLight;
          Font.Color := clHighLightText;
        end;
        FillRect(R);
        TextRect(R, R.Left + 2, R.Top, Item.Caption);
      end;
      DefaultDraw := False;
    end;