比如
column1绑定字段1,字段1的值为0,1,2但我想在column1上显示为通过,未通过,待通过。而字段1没有关联字段。怎样才能达到目地?

解决方案 »

  1.   

    还是通过SQL语句来解决吧!!Select 状态=
    Case backFlag 
         when 0 then '通过'
         when 1 then '未通过'
         when 2 then '待通过'
    end
    from tpIndetail
      

  2.   

    1、在ADOQuery中双击,把需要的字段添加进来;
    2、选中要绑定的字段1,在OnGetText事件里写如下代码:
    procedure OnGetText(Sender: TField;
      var Text: String; DisplayText: Boolean);
    begin
       if sender.Value=0 then
          text:='通过'
       else if sender.Value=1 then
          text:='未通过'
       else if sender.Value=2 then
          text:='待通过'
       end;
    end;
      

  3.   

    同意楼上
    在ongettext中写;
    如果你显示后还需要做编辑的话;
    可以用calcufield();
      

  4.   

    1.在SQLServer中用case when else end
    2.在Oracle 中用Decode
      

  5.   

    to yzykjh(多米诺骨牌):
    如果ADOQuery是动态的怎么实现呢?
      

  6.   

    动态的也可以的;
    你先在设计期将adoquery连接通;
    然后将字段对象加入到adoquery中
    然后写好你的程序,再断开你的adoquery和数据库的连接
    再去动态连接就可以了;
    实际上手工添加也可以,只不过麻烦;
    用上面的方法添加字段对象之后看看窗体中的成员声明就知道了
    和手工没什么区别的;
    ongettext和oncalculate都可以用;
      

  7.   

    这可以在DBGrid控件的OnDrawColumnCell事件中来处理,但是DBGrid不能和表格邦定,可以使用一个TQuery控件,然后需要增加代码,示例如下:if Column.FieldName = '你指定的字段' then
    begin
        DBGrid.Font.Color := clDefault;
        DBGrid.Canvas.FillRect(Rect);
        if (你的数据库.你的TQuery.FieldByName('你指定的字段').AsInteger = 0) then
          self.DBGrid.Canvas.TextOut(Rect.Left,Rect.Top,'通过')
        else if (你的数据库.你的TQuery.FieldByName('你指定的字段').AsInteger = 1) then
          self.DBGrid.Canvas.TextOut(Rect.Left,Rect.Top,'已通过')
        else if (你的数据库.你的TQuery.FieldByName('你指定的字段').AsInteger = 2) then
          self.DBGrid.Canvas.TextOut(Rect.Left,Rect.Top,'待通过')
        end;
    end
    else
        self.DBGridVoiceBox.DefaultDrawColumnCell(Rect,DataCol,Column,state);