请问:如何在dbgrid中改变记录行的背景色?
还有怎样打印dbgrid中的内容(并支持分页打印)?
  公司要我作一个筛选异常数据的软件,要求在dbgrid中用红色标示出有异常数据的行,想了很久,也做不到,列颜色可以改变查行不可以,dbgrid中好像没这属性?
(急 急 急,在线等,百分送.)

解决方案 »

  1.   

    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin  with DBGrid1 do
      begin
        if gdSelected in State then
        begin
          Canvas.Brush.Color := clSkyBlue;
          Canvas.Font.Color := clRed;
        end;
        DefaultDrawColumnCell(Rect, DataCol, Column, State);
      end;end;
      

  2.   

    在DBGrid1DrawColumnCell中加上,异常数据将会变成红色if(ADOQuery.Active)
    begin
     if(ADOQuery.RecordCount >0)
     begin
      if (ADOQuery.FieldByName(字段).Value=异常)
      begin
        DBGrid1.Canvas.Font.Color = ClRed;
        DBGrid1.DefaultDrawDataCell(Rect, Column.Field, State);
      end;
     end; 
    end;
      

  3.   

    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
       if gdSelected in State then Exit;
       if Table1.FieldByName('age').AsInteger >0 then
         (Sender as TDBGrid).Canvas.Brush.Color := clInfoBk //定义正常背景颜色
       else//年龄不能为负
         (Sender as TDBGrid).Canvas.Brush.Color := clRed; //异常数据背景颜
       (Sender as TDBGrid).DefaultDrawColumnCell(Rect, DataCol, Column,  State); 
    end;
      

  4.   

    还有怎样打印dbgrid中的内容(并支持分页打印)?