在DBGrid的OnDrawDataCell事件中写如下代码:if DataSet.AsInteger < 5 then
  with DBGrid.Canvas do
  begin
    Brush.Color := clRed;
    DBGrid.DefaultDrawDataCell(Rect, Field, State);
  end;

解决方案 »

  1.   

    onDrawDataCell是在什么时候触发的? 我写了上面的代码好象没反应.
    我是想在浏览数据的FORM一打开,就根据数据来改变某些行的颜色,表示这几行的数据
    已经超过警戒线.应该怎么做呢?
      

  2.   

    //能达到你的要求:with DBGrid.Canvas do begin
     if DataSet.AsInteger < 5 then
        Brush.Color := clRed;
     DBGrid.DefaultDrawDataCell(Rect, Field, State);
    end; 
      

  3.   

    你还是在DBGrid1DrawColumnCell事件中写代码为好。
      

  4.   

    这样吧:
    在DBGrid1的OnDrawDataCell事件中写如下代码:
    if Table1.FieldByName("f1").AsInteger<5 then
      begin
        DBGrid1.Canvas.Font.Color:=clAqua;
        DBGrid1.Canvas.Brush.Color:=clBlack;
      end;
      DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
      

  5.   

    Do not write an OnDrawDataCell event handler. OnDrawDataCell is obsolete and included for backward compatibility. Instead, write an OnDrawColumnCell event handler.用OnDrawColumnCell事件吧,先把OnDrawDataCell事件删掉。BTW: DataSet.AsInteger < 5是什么意思?看不懂啊,好象只有Dataset.FieldByName('xxx').AsInteger吧?