现在我用TcxGridTableView显示数据N行,现在做隔行颜色处理在
procedure TfrmMain.TcxGridTableViewCustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
  if (AViewInfo.RecordViewInfo.Index Mod 2 = 1) then
  begin
    ACanvas.Brush.Color := Clgreen;
  end
  else
  begin
    ACanvas.Brush.Color := clred;
  end;
end 加入事件,可以达到隔行颜色,可是当加多了行数时, 用鼠标滚轮滚去时出现连续N行是一个颜色,根本没达到分行不同颜色的效果,有什么方法可处理,用滚动一次刷新一次?? 会不会很慢,大家有什么好办法没??? 

解决方案 »

  1.   

    LZ自己變通一下:procedure TRes_Cq_TxSh_F.cxGrid1DBTableView1CustomDrawCell(
      Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
      AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    var
      CheckValue:Integer;
      CxColumn:TcxGridDBColumn;
    begin
      inherited;
      CxColumn:=(Sender as TcxGridDBTableView).GetColumnByFieldName('FLAG');
      if CxColumn=nil then Exit;
      if SameText(AViewInfo.Item.Name,CxColumn.Name) then
      begin
        CheckValue:=StrToInt(AViewInfo.GridRecord.Values[cxGrid1DBTableView1Column16.Index]);
        if(CheckValue=0) then
        begin
          AViewInfo.Focused;
          ACanvas.Brush.Color:=clRed;
        end;
        if(CheckValue=1) then
        begin
          AViewInfo.Focused;
          ACanvas.Brush.Color:=clGreen;
        end;
        if(CheckValue=2) then
        begin
          AViewInfo.Focused;
          ACanvas.Brush.Color:=clFuchsia;
        end;
      end;
    end;
      

  2.   

    如果只是為了隔行做color處理:
    你可以使用cxStyleRepository控件來聯合處理
      

  3.   

    事件句柄找错了!应该在TcxGridTableView.OnGetContentStyle中做处理。cxGird的帮助中就有隔行着色的例程。
      

  4.   

    对啊,直接在cxStyleRepository设置好就行了的..
      

  5.   


    在Styles中有一个ContentOdd属性,设置一下就可以了。
      

  6.   

    cxStyleRepository--styles--contentodd--(new color)...
      

  7.   

    cxGridDBTableView1:
    设置ContentEver 和ContertOdd的cxstyle即可...