继承下来的页面CXGRID 白色与蓝色交替,即所有继承下来的页面上的CXGRID默认是一行白色一行蓝色 交替着。
必须要继承,这是条件。而现在是在继承的基础上 根据条件 来实现红色(即满足条件的 为红色,不满足的颜色不变),问题在于 点击本来是红色的地方  颜色会变成别的颜色。(估计是颜色叠加的问题?)
看代码 procedure TbsWdhacInsuranceFollowUp.cxDBInsuranceRemindContendCustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var ATextToDraw:String;
    ARec: TRect;
    Is_Over:Boolean;//是否超过执行期间
    val:string;
begin
//  红色表色超期跟进或未跟进;
  inherited;
  val:=VarAsType(vartostr(AViewInfo.GridRecord.Values
  [cxDBInsuranceRemindContendIS_FOLLOWED.Index]), varString);
  arec := aViewInfo.Bounds;
  if SameText(val, bsStatusDict.DICT_IS_NO) then  
  begin
    Is_Over :=((StrToDateTime(FormatDateTime('yyyy-mm-dd',Now))-StrToDateTime(FormatDateTime('yyyy-mm-dd',fcds.FieldByName('REMIND_PLAN_DATE').AsDateTime))<5)
              and  (StrToDateTime(FormatDateTime('yyyy-mm-dd',fcds.FieldByName('REMIND_PLAN_DATE').AsDateTime))<=StrToDateTime(FormatDateTime('yyyy-mm-dd',Now))));
    if not Is_Over then
    begin
      ACanvas.Canvas.Brush.Style := bsSolid;
      ACanvas.Canvas.Brush.Color := clWindow;
      ACanvas.Canvas.Font.Color := clRed;
      ACanvas.Canvas.FillRect(aRec);
    end
    else
    begin
      ACanvas.Canvas.Brush.Style := bsSolid;
      ACanvas.Canvas.Brush.Color := clWindow;
      ACanvas.Canvas.Font.Color := clBlack;
      ACanvas.Canvas.FillRect(aRec);
    end;
  end;
  if SameText(val,bsStatusDict.DICT_IS_YES) then
  begin
    Is_Over:=(StrToDateTime(FormatDateTime('yyyy-mm-dd',fcds.FieldByName('FOLLOW_DATE').AsDateTime))-StrToDateTime(FormatDateTime('yyyy-mm-dd',fcds.fieldbyname('REMIND_PLAN_DATE').AsDateTime))<5);
    if not Is_Over then
    begin
      ACanvas.Canvas.Brush.Style := bsSolid;
      ACanvas.Canvas.Brush.Color := clWindow;
      ACanvas.Canvas.Font.Color := clRed;
      ACanvas.Canvas.FillRect(aRec);
    end
    else
    begin
      ACanvas.Canvas.Brush.Style := bsSolid;
      ACanvas.Canvas.Brush.Color := clWindow;
      ACanvas.Canvas.Font.Color := clBlack;
      ACanvas.Canvas.FillRect(aRec);
    end;
  end;
end;结果是 点击某一行  颜色会变 。
如何实现 颜色不变  即红色就是红色,点击也不变色

解决方案 »

  1.   


    cxDBInsuranceRemindContendStylesGetContentStyle(
      Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
      AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);这里控制 也没用
      

  2.   

    好像不用这么复杂吧,用 TcxGridTableView->Styles->OnGetContentStyle 来设置着色是最好的方法。
    //根据你的代码,应该用这个事件 ,你自己加一个 cxStyle1,cxStyle2, 设置相应的前景,背景色及字体
    procedure TbsWdhacInsuranceFollowUp.cxDBInsuranceRemindContendGetContentStyle(
     Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
      AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
    var
      tmpTcxGridDBColumn : TcxGridDBColumn ;
     val:string;
     ATextToDraw:String;
        ARec: TRect;
        Is_Over:Boolean;//是否超过执行期间
    begin
        tmpTcxGridDBColumn:= cxDBInsuranceRemindContend.GetColumnByFieldName('IS_FOLLOWE') ;
        if tmpTcxGridDBColumn<>nil then
        begin
           val:=VarAsType(vartostr(if ARecord.Values[cxDBInsuranceRemindContendIS_FOLLOWED.Index]), varString);
        if SameText(val, bsStatusDict.DICT_IS_NO) then  
      begin
        Is_Over :=((StrToDateTime(FormatDateTime('yyyy-mm-dd',Now))-StrToDateTime(FormatDateTime('yyyy-mm-dd',fcds.FieldByName('REMIND_PLAN_DATE').AsDateTime))<5)
                  and  (StrToDateTime(FormatDateTime('yyyy-mm-dd',fcds.FieldByName('REMIND_PLAN_DATE').AsDateTime))<=StrToDateTime(FormatDateTime('yyyy-mm-dd',Now))));
        if not Is_Over then
        begin
           AStyle:=cxStyle1 ;
        end
        else
        begin
           AStyle:=cxStyle2 ;
        end;
        end;
      end;
    end;