我的表有个字段是int型的,我只在里面保存1或0其中一个值,我想在DBGrid里面显示的时候如果是1就显示是,如果是0就显示否。可不可能实现?

解决方案 »

  1.   

    用计算字段,
    或者在DBGrid1DrawColumnCell中判断是否是1,如果是,就把字体颜色和背景颜色改为一样,这样用户就看不到了
      

  2.   

    打開該字段對應的GetText,SetText事件,加入代碼:
    procedure TForm1.ADOQuery1Field1GetText(Sender: TField; var Text: String;
      DisplayText: Boolean);
    begin
      if Text='0' then
        DisplayText:='否'
      else
        DisplayText:='是';
    end;procedure TForm1.ADOQuery1Field1SetText(Sender: TField;
      const Text: String);
    begin
      if (Text='是')or(Text='1')  then
        Sender.AsInteger :=1
      else
        Sender.AsInteger :=0;end;
      

  3.   

    在sql里面写
    select a,b,c,'是'as dd from table where d=1
    union
    select a,b,c,'否'as dd from table where d<>1
      

  4.   

    “select a,b,c,'是'as dd from table where d=1
    union
    select a,b,c,'否'as dd from table where d<>1”
    在DBGRID编辑后怎样保存?怎样转回Integer型?
      

  5.   

    这样应该比较简单.
    select (case md_int when 1 then '是' when 2 then '否' end) as vt_int,
           md_field1,md_field2
    from table1
      

  6.   

    在该字段对象(在TTable或TQuery等控件上双击后添加、选取)的OnGetText事件里写:
    if (Sender->AsBoolean)
         Text = "是";
    else
         Text = "否";
      

  7.   

    select case when field1=1 then ' +''''+'是'+''''+' else '+''''+'否'+''''+'end AS field2 from table
      

  8.   

    select decode(md_int,1,'是','否') as vt_int,md_field1,md_field2
    from table1
      

  9.   

    select decode(a,'1','空','是') from abc
      

  10.   

    我也同意 ZbDerek(虚竹) 的做法就是从数据库中读出的时候就进行处理, ZbDerek(虚竹)的语句是针对SQLSERVER的,如果是Oracle则应改为:graty(graty) 的写法!!!
      

  11.   

    zhangqiufk(真言)的处理办法比较好。
      

  12.   

    用DECODE就行啊
    select decode(field1,1 '是',‘否’) from table
      

  13.   

    但是如果是通过 select decode(field1, 1, '是','否') from table,则不论在DBGrid中是否允许对该列进行修改,你都无法修改该列了!!!不知怎回事???