如何让dbgrid负值显示为零或空有好多列。

解决方案 »

  1.   

    在数据集里面设置吧,设置一个字段的OnGetText事件为if Sender.AsInteger < 0 then Text := '0';把其它需要处理的字段都指向这个事件!
      

  2.   

    很多方法呀
    确定太多就用for循环吧
    for i:=... to ... do
    begin
    if(DBGrid.columns.items[i].Field.asinteger<0)then
    DBGrid.columss.items[i].field.asinteger:=0;
    end;
    ...自已填上初值终值,不连续的就分开来判断。
      

  3.   

    1楼正解,不过也可以用sql直接显示case...
      

  4.   

    它自己有个重绘事件onDrawDataCell
    procedure TForm1.DBGrid2DrawDataCell(Sender: TObject; const Rect: TRect;
      Field: TField; State: TGridDrawState);
    begin
      if uppercase(Field.FieldName)='字段名' then
      begin
        DBGrid2.Canvas.FillRect(Rect);
        if ADOTable1.Fieldbyname('字段名' ).value<0 then
          DBGrid2.Canvas.TextOut(Rect.left+2,Rect.top+2,'0    ');   
      end;
    end;
      

  5.   

    我的记录集是存储过程,以上方法都不行,我看还是在SQL里用case好了。
    谢谢各位!