TdxTreeList如何实现间隔色(奇数行一种颜色,偶数行一种颜色。)?

解决方案 »

  1.   

    不知道TdxTreeList是什么控件,但它应该有DrawItem事件,你可以参照下面的改一下:
    procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView; 
      Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean); 
    begin 
      with ListView1.Canvas.Brush do 
      begin 
        case Item.Index of 
          0: Color := clYellow; 
          1: Color := clGreen; 
          2: Color := clRed; 
        end; 
      end; 
    end; 
      

  2.   

    procedure TForm1.dxTreeList1CustomDrawCell(Sender: TObject;
      ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode;
      AColumn: TdxTreeListColumn; ASelected, AFocused, ANewItemRow: Boolean;
      var AText: String; var AColor: TColor; AFont: TFont;
      var AAlignment: TAlignment; var ADone: Boolean);
    begin
    if odd(ANode.AbsoluteIndex) then
      AColor:=clred;
    end;
      

  3.   

    odd(ANode.AbsoluteIndex)指的判断奇偶数
    if odd(ANode.AbsoluteIndex) then
      AColor:=clred
    else
      AColor:=clblue;
    刷2种颜色