本帖最后由 zylmp 于 2011-12-22 15:06:13 编辑

解决方案 »

  1.   

    DrawCell
    根据条件判断画上颜色
      

  2.   

    我知道是在CustomDrawCell写代码,但是代码怎么写呢?
      

  3.   


    procedure TForm1.cxGrid1TableView1CustomDrawCell(
      Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
      AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    var
      Value: string;
    begin
      if SameText(Aviewinfo.Item.Name,cxGrid1TableView1.Columns[0].Name) then
        Value := AViewInfo.GridRecord.Values[0];
      if Value = 'BB' then
      begin
        Aviewinfo.Focused;
        ACanvas.Canvas.Brush.Color := clRed;
      end;
    end;
      

  4.   

    ID这一列忘记加了,这里就只有Test列的,楼主自己琢磨琢磨吧
      

  5.   

    另外OnGetContentStyle事件也可以满足楼主的需求
      

  6.   

    procedure TForm1.cxGrid1TableView1CustomDrawCell(
      Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
      AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    begin
      if AViewInfo.GridRecord.Values[1] = 'BB' then
        ACanvas.Canvas.Brush.Color := clRed;
    end;