本帖最后由 wanglaoji60 于 2010-04-01 22:42:46 编辑

解决方案 »

  1.   

    http://topic.csdn.net/t/20060404/10/4661258.html
    http://topic.csdn.net/u/20071111/20/649F1BD8-920A-4EBE-B666-D9EF397AB66C.html
      

  2.   

    你很搞哦,你每次判断条件都是当前记录和你的时间做比较,比较完了当然是所有都刷新了。改成判断cell里面的字符和你的edit1里的字符做比较,不要用数据库里的当前记录的日期值,你现在成了用一个字符和一个全局变量做比较了,当然不对。用AViewInfo.Text和edit1.Text比较。如果你的其他没有错误的话。
      

  3.   

    在 onGetContentStyle事件中处理,用这个控件StyleRepository去定义不同的style
    procedure TFrmItemInfo.Contvew_MStylesGetContentStyle(
      Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
      AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
    begin
      if ARecord is TcxGridDataRow then
      begin
        if (ARecord.Values[1] = edit1.Text) then
          AStyle := cxStyle18;
        else
          AStyle := cxStyle46;
      end;
    end;
      

  4.   

    TO mysterx:procedure TForm1.cxGrid1DBTableView1CustomDrawCell(
      Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
      AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    begin
      //取得今天的日期放到edit1.text里面
      edit1.Text :=datetostr(date);
      //下面一句判断代码改好了
      if aviewinfo.Text =edit1.Text then
      ACanvas.Canvas.Font.Color:=clRed
      else
      ACanvas.Canvas.Font.Color:=clblack;
    end;这样执行一下,确实OK了。
    但是只有符合条件的这一个日期字段变红色。我想这个日期字段所在的整条纪录都变红色,该咋办呢?
    盼指教!
      

  5.   

    这个使用DBGRID控件显示的,代码如下,没有任何问题。符合条件的整行的文字都变成了红色。
    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
      edit3.Text :=dbgrid1.DataSource.DataSet.FieldByName('日期').AsString;
      edit1.Text :=datetostr(date);
      //满足条件的变红色(字的颜色变红色)
      //TO mysterx:为什么下面这样写能行呢?
      if dbgrid1.DataSource.DataSet.FieldByName('日期').AsString=edit1.Text then
      begin
      DBGrid1.Canvas.Font.Color   :=   clRed;
      DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
      end
    end;
      

  6.   


    阿三的方法。
    建议不要使用StringGrid的方法。
      

  7.   

    LZ,把ACanvas.Canvas.Font.Color:=clRed
    这句改成ACanvas.Font.Color:=clRed,就可以了
      

  8.   

    就两种情况的话,下面不要,
    else
      ACanvas.Canvas.Font.Color:=clblack;
      

  9.   

    To pooplin:改成ACanvas.Font.Color:=clRed 也不行啊
      

  10.   

    机器上没装Delphi,你要确定你的CustomDraw是在哪个对象上。TableView上还是在某个字段上。字段上针对一个,TableView上针对一行。应该是……有段时间没接触了,先尝试下。
      

  11.   

    嘿嘿,解决问题了,代码:procedure TForm1.cxGrid1DBTableView1CustomDrawCell(
      Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
      AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    {参数 Sender: 你要实现特效的TableView;
     ACanvas: 画布, 这个参数比较重要, 就是用这个参数画出特效;
     AViewInfo: 自定义条件的来源; 从这个参数中获取单元格值;
     ADone: 设为真就不会Paint. }
    begin
        edit1.text=datetostr(date);
    if  AViewInfo.GridRecord.Values[3]=edit1.text then
        {AViewInfo.GridRecord.Values[3]:取得某一列(3是代表第四列,我的程序里面第四列是日期的字段)中的单元格的数据。}
        //ACanvas.Brush.Color := clred;//背景色改变
        ACanvas.Font.Color:=clred;//字体颜色改变
    end;这样,在日期字段中所有等于今天的纪录的字体变红色,整条纪录都变成了红色,而不只是日期字段单元格变色。