请问如何将dbgrid中的负数变为正数,并显示为红色?另外,不改变原数据的统计。请指教!

解决方案 »

  1.   

    procedure Tinfo.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
            if query1.FieldByName(’all’).asstring>40’ then
            begin
                    dbgrid1.Canvas.Font.Color:=clred;
                    dbgrid1.Canvas.Brush.color:=clyellow;
            end
            else
            begin
                    dbgrid1.Canvas.Font.Color:=clblue;
                    dbgrid1.Canvas.Brush.color:=clyellow;
                    end;
     
            dbgrid1.DefaultDrawColumnCell(rect,datacol,column,state);
    end;
      

  2.   

    贴子分太少拉,呵呵
    替你解决最主要的问题吧,变为红色:
    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin  
      if adoquery1.FieldByName('num').Asinteger<0 then  DBGrid1.Canvas.Font.Color:=clRed;
      DBGrid1.DefaultDrawColumnCell(rect,DataCol,column,state);
    end;