要求在某条数据满足条件时,满足该条件的那行会变色,但遇到了麻烦。
虽然满足条件的那行会变色,但鼠标点击该行后,在点别的行,被点的那行也同样会变色,不知如何解决,还请高手出手相助

解决方案 »

  1.   

    代码如下
    procedure TForm1.cxGDBTVCustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    begin
      if ADOQuery1.FieldByName('Age').AsFloat > 20 then      
      begin
        TcxCustomGridTableView(Sender).ViewInfo.Canvas.Brush.Color := clYellow;
        TcxCustomGridTableView(Sender).ViewInfo.Canvas.Font.Color := clBlack;
      end;
      

  2.   

    樓主設置了滿足條件的顏色,還需要設置在選中時的顏色
    下面是DBGridEh的OnDrawCell的定義DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumnEh; State: TGridDrawState);判斷是否選中可以用如下代碼:
    if gdSelected in state then由於我還沒有搞過TcxCustomGridTableView,所以以TDBGridEh為例
      

  3.   

    procedure TForm1.cxGDBTVCustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    begin
      if ADOQuery1.FieldByName('Age').AsFloat > 20 then      
      begin
        TcxCustomGridTableView(Sender).ViewInfo.Canvas.Brush.Color := clYellow;
        TcxCustomGridTableView(Sender).ViewInfo.Canvas.Font.Color := clBlack;
      end;
      else
      begin
        TcxCustomGridTableView(Sender).ViewInfo.Canvas.Brush.Color := clWhite;
        TcxCustomGridTableView(Sender).ViewInfo.Canvas.Font.Color := clBlack;
      end;
      // 你找找看有沒有斷定當前行是否選擇的屬性.
      // 同樓上的那樣
    end;
      

  4.   

    借宝地问个问题: 如何设置cxGrid的Image类型字段的显示高度和宽度??,没人遇到过吗?
      

  5.   

    借宝地问个问题: 如何设置cxGrid的Image类型字段的显示高度和宽度??,没人遇到过吗?
      

  6.   

    多谢各高手的帮助,但问题未解决
    duanhai(段海) 给出的提议不错,但我找DevExpress QuantumGrid的state相关属性没找到,而且DbGridEh控件也不用设,就可达到我想要的效果
    konhon(优华) 给出的代码我也写过,就是不行我才上网找高手求助
      

  7.   

    这是我一个cxGrid中的例子,也没改造,只好自己看了.
    procedure TFm_Kccx.GD_RkcxBTCustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    var sYxq,sSjzt:string;
        dYxq:TDateTime;
        Sjzt:Integer;
        BColor,FColor:TColor;
    begin
      sYxq:=Trim(VarAsType(AViewInfo.GridRecord.DisplayTexts[GD_RkcxBTYxq.Index], varString));
      sSjzt:=Trim(VarAsType(AViewInfo.GridRecord.DisplayTexts[GD_RkcxBTSjzt.Index], varString));
      Try
        dYxq:=StrToDate(sYxq);
      Except
        dYxq:=Now;
      End;
      Try
        Sjzt:=StrToInt(sSjzt);
      Except
        Sjzt:=1;
      End;
      BColor:=ACanvas.Canvas.Brush.Color;
      FColor:=ACanvas.Canvas.Font.Color;
      if ( (Trunc(dYxq)<=Trunc(Now)) and ((Sjzt and 4)>0) ) then begin
        BColor :=$00B3BBEA ;//clred;
        FColor := clBlue;
      end;
      if ( (Trunc(dYxq)<=Trunc(Now)) and ((Sjzt and 4)=0) ) then begin
        BColor :=$00B3BBEA ;////$00C8CEF0;
        FColor := clblack;
      end;
      if ( (Sjzt and 2)>0 ) then begin  //坏卡
        BColor :=$0079FFFF ;////$00C8CEF0;
        FColor := clblack;
      end;
      if AViewInfo.Selected then begin
        BColor :=clNavy ;
        FColor :=clwhite;
      end;
      ACanvas.Canvas.Brush.Color:=BColor;
      ACanvas.Canvas.Font.Color:=FColor;
    end;
      

  8.   

    OK
    belllab(菜鸟) 的方法可以!谢谢!