关于DBGRID显示特定颜色的问题!
具体是这样的,我从EXCEL表导入数据到access数据库的,然后对导入的数据进行辨别,例如:我导入的数据里面有“时间”这个字段,在某一个时间以前是一个颜色,某一个时间以后是一个颜色!!应该是在DBGRID里面写呢??还是我这个导入按钮里面写???具体怎么写呢??

解决方案 »

  1.   

    DBGRID的自画事件中根据某个字段值去画单元格的底色
      

  2.   

    procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
      Field: TField; State: TGridDrawState);
    begin
        if Query1.FieldByName('时间).AsString='2009-10-14' then
           DBGrid1.canvas.Font.color:=clred
      else
       begin
        if Query1.FieldByName('时间).AsString='2009-10-13' then
           DBGrid1.Canvas.Font.Color:=clGreen;
        end;
       DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
    end;
      

  3.   

    dbgrid的事件 DrawColumnCell代码如获3楼写的
      

  4.   

    procedure TForm1.DBGridEh1DrawDataCell(Sender: TObject; const Rect: TRect;
      Field: TField; State: TGridDrawState);
    begin
    if adoQuery1.FieldByName('ComeTime).AsString >= 09:10 then[Error] Unit1.pas(142): Missing operator or semicolon
          DBGridEh1.canvas.Font.color:=clred;
    [Error] Unit1.pas(142): Missing operator or semicolon
      else
      begin 
        if adoQuery1.FieldByName('GoTime).AsString <= 17:30 then
          DBGridEh1.Canvas.Font.Color:=clGreen;
        end;
      DBGridEh1.DefaultDrawColumnCell(Rect,DataCol,Column,State);end;
      

  5.   

    下面是代码。调试过了,但是颜色没变呢???
    procedure TForm1.DBGridEh1DrawDataCell(Sender: TObject; const Rect: TRect;
      Field: TField; State: TGridDrawState);
    begin
    if adoQuery1.FieldByName('ComeTime').AsString >= '09:10' then
          DBGridEh1.canvas.Font.color:=clred;
    if adoQuery1.FieldByName('GoTime').AsString <= '17:30' then
          DBGridEh1.Canvas.Font.Color:=clGreen;
    end;
      

  6.   

    DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
    加上这句
      

  7.   

    加了之后,报错!!
    [Error] Unit1.pas(146): Undeclared identifier: 'DataCol'
      

  8.   

    详细,你看http://topic.csdn.net/u/20091014/16/585ed71d-079a-4b55-8b07-4d6edbede37a.html?seed=203747105&r=60410080#r_60410080这是两个事件,在DrawDataCell中得调用DBGridEh1.DefaultDrawDataCell(Rect,Field,State);
    它自己的,不能调用DefaultDrawColumnCell
      

  9.   

    procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; 
      Field: TField; State: TGridDrawState); 
    begin 
        if Query1.FieldByName('时间).AsString='2009-10-14' then 
          DBGrid1.canvas.Font.color:=clred 
      else 
      begin 
        if Query1.FieldByName('时间).AsString='2009-10-13' then 
          DBGrid1.Canvas.Font.Color:=clGreen; 
        end; 
      DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State); 
    end;