怎么样使满足条件的数据在dbgrid里显示为红色背景?

解决方案 »

  1.   

    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
      if {条件} then with TDBGrid(Sender) do
      begin
         Canvas.Brush.Color := clRed;
         DefaultDrawColumnCell(Rect, DataCol, Column, State);
      end;
    end;————————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    ————————————————————————————————————
      

  2.   

    在dbgrid的哦onDrawColumnCell事件里写代码:
    如下:
    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
      if dbgrid1.DataSource.DataSet.FieldByName('TG011').Value>1000 THEN
      //如果某一字段值大于1000
      begin
       dbgrid1.Canvas.Brush.Color:=clred;
       dbgrid1.DefaultDrawColumnCell(rect,datacol,column,state);
      end;
    end;