改变底色
procedure TscFrmProducePlan.DBGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin
  if ADOQuery1.FieldByName('bUrgentSign').AsBoolean = True then
  begin
    DBGrid1.Canvas.Brush.Color := clRed;
    DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
  end;
end;

解决方案 »

  1.   

    改变底色
    procedure TscFrmProducePlan.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
      if cdsX.FieldByName('bUrgentSign').AsBoolean = True then
      begin
        DBGrid1.Canvas.Brush.Color := clRed;
        DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
      end;
    end;
      

  2.   

    在DBGridD的OnDrawColumnCell中写代码,
    格式类似
       if .........
         then Grid1.Brush.Color:=.......
         else grid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
      

  3.   

    老兄们,照你们的方法,我的确能够使DBGird的背景变色,但是为什么是全部都变成了红色了?我的想法是某个特定的区域变色啊。
      

  4.   

    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
    if gdselected in state then
    begin
        dbGrid1.Canvas.Font.Color:=clwhite;
        dbGrid1.Canvas.Brush.color:=clgreen;
        dbgrid1.DefaultDrawColumnCell(rect,datacol,column,state);
    end;
      

  5.   

    DBGrid1DrawColumnCell事件
    不过之前,要设置一下dbgrid
      

  6.   

    很抱歉 给你的短信息中有点出入 解决方法如下
    procedure TForm1.DBGrid1.DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
      if Column.Field = ADOQuery1.FieldByName('xx') then
      begin
        if Column.Field.AsInteger = 0 then
        begin
          DBGrid1.Canvas.Brush.Color := clRed;
          DBGrid1.Canvas.FillRect(Rect);
          DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
        end;
      end;
    end;