看了很多资料,发现dbgrideh只能设定特定行或者列的颜色,如果要设定特定单元格的颜色呢?例如
时间    是否预计
12:00      true
13:00      false
根据是否预计字段来确定时间字段的字体颜色

解决方案 »

  1.   

    改变字体色还真不太清楚,不过给你个改变cell背景色的例子
    手头没d,都是随手写的,所以有的单词可能拼错了
    在getcellparam事件里if column.index=X then  //就是你要判断的哪个字段的索引
      if dbgrideh.datasource.dataset.fields[column.index].asstring='true' then
         background:=clxxxx
      else
         background:=clxxxx;
      

  2.   

    在Grid的onDrawColumnCell   事件中写
      if     ADOTable1.filedbyname('某字段').asboolean = true   then
        begin
                                Grid.Canvas.Font.Color   :=   Clyellow;
                                Grid.DefaultDrawColumnCell(Rect,   DataCol,   Column,   State);
        end; 
      

  3.   

    procedure TForm1.DBGridEh1GetCellParams(Sender: TObject; Column: TColumnEh;
      AFont: TFont; var Background: TColor; State: TGridDrawState);
    begin
      if column.FieldName = '时间' then
      if dbgrideh1.datasource.dataset.FieldByName('是否预计').asstring='true' then
        AFont.Color:= clRed
      else
        AFont.Color:= clBlue;
    end;