我能想到的是:后台存储过程对每个字段“格式化”后输出,可是字段很多,写起来太烦了。

解决方案 »

  1.   

    onDrawDataCell事件
    if (Sender as TDBGrid).DataSource.DataSet.FieldByName('CustNo').AsString = '' then 
      TextOut(Rect.Left+2,Rect.Top+3,'无');
      

  2.   

    做一个固化字段,然后在字段的onGetText中处理
      

  3.   

    使用下面的函数: 
      
    function ChangeZeroToSpace(Sender: TDBGrid): Boolean;
    var
      RowCount, ColCount: integer;
      RowCycle, ColCycle: integer;
    begin
      ColCount := TStringGrid(Sender).ColCount;
      RowCount := TStringGrid(Sender).RowCount;
      for RowCycle := 0 to RowCount do
        for ColCycle := 0 to ColCount do
        begin
          if TStringGrid(Sender).Cells[ColCycle, RowCycle] = '零' then
            TStringGrid(Sender).Cells[ColCycle, RowCycle] := '空'
        end;
    end;注: 要引用单元: Grids 
      

  4.   

    不好意思,刚才函数忘了写返回值(修改下):使用下面的函数, 用DBGrid控件作为 Sender 的实参。
      
    function ChangeZeroToSpace(Sender: TDBGrid): Boolean; 
    var 
      RowCount, ColCount: integer; 
      RowCycle, ColCycle: integer; 
    begin 
      Result := False;
      ColCount := TStringGrid(Sender).ColCount; 
      RowCount := TStringGrid(Sender).RowCount; 
      for RowCycle := 0 to RowCount do 
        for ColCycle := 0 to ColCount do 
        begin 
          if TStringGrid(Sender).Cells[ColCycle, RowCycle] = '零' then 
            TStringGrid(Sender).Cells[ColCycle, RowCycle] := '空' 
        end; 
      Result := True;
    end; 注: 要引用单元: Grids 
      

  5.   

    SWind 的方法只能对单个字段有效啊,我可是n个字段,那还是要一个个写,岂不是也很麻烦?
    hege3344520 的方法简单地说就是遍历所有的单元格,效率太低。
    两个方法都不能采用。期待其他答案。
      

  6.   


    你应该写一个公共的GetText过程,处理字段为null的情况,然后动态将字段的OnGetText指向你的公共GetText事件