DbGrid或DbGridEh中!有无办法实现零值不显示(即显示为空白)?急!急!急!

解决方案 »

  1.   

    SQL中,0的时候你把它转换成NULL值就可以了
      

  2.   

    在列的OnGetText中写代码 
    procedure TdmMain.FieldXXXGetText(Sender: TField;
      var Text: String; DisplayText: Boolean);
    begin
      if TField(Sender).AsInteger = 0 then Text := '';
    end;最简单的方法,可惜分太少了。~_~
      

  3.   

    select 
    (case when field =0 then null else field) 
    from table
      

  4.   

    select 
    (case when field =0 then null else field end) 
    from table
      

  5.   

    fim(镇江DJ)(DJ=DelphiJava:
       我试了一下您的方法,没有成功!
       我用的是DbGridEh,没有设置字段对象,但设置了DbGridEh的列对象并设置了Displayformat为#,##0.00。我按您的指点重建了一个DbGrid,并在dataset(AdoQuarray)中设置字段对象并取消DisplayFormat的设置角不管用,我希望可在VCL控件中或Delphi程序代码中直接解决这个问题。
        windindance(风舞轻扬)的方法我还没试,我估计他的方法可能管用,但如果我的SQL语句包含的字段较多,则这个SQL写起来会告别长,挺费事的。
        各位高手有没有更好的办法。
      

  6.   

    我只会windindance(风舞轻扬)的方法友情up
      

  7.   

    select 
    (case when field =0 then null else field end) 
    from table
      

  8.   

    在来一个参考一下,写OnDrawColumnCell事件,例如下:
    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
      if Column.FieldName = 'TaxRate' then
        if Column.Field.AsInteger = 0 then
          TDBGrid(Sender).Canvas.FillRect(Rect);
    end;
      

  9.   

    hahafan(注意!此人前途迷茫) 先生的方法刚才也试了一下还是没管用。