帮帮我,我有一个表一个字段是整数类型的,如1,2,3...,等,我想在Grid里面这个字段不显示这些,我想转换显示,假设如果是"1"就显示“中国”如果是"2"就显示“美国”....等,不知道如何做?

解决方案 »

  1.   

    在Dataset中选中Field 在其事件中中可以ongetText()设定你的值
      

  2.   

    procedure TForm1.ADOQuery1IntFieldGetText(Sender: TField; var Text: String;
      DisplayText: Boolean);
    begin
      if  TIntegerField(Sender).AsInteger =1 then
      begin
        Text:='中国';
      end;
    end;
      

  3.   

    if ADOQuery1.FieldByName('attribute_id').AsString=inttostr(1) then
       DBGrid1.Columns[0].FieldName:='中国';
      

  4.   

    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
      sg := (Sender as TStringGrid);
      CellText := sg.Cells[ACol, ARow];
      sg.Canvas.Font := sg.Font;
      if (ACol = 0) then
      begin
        case _StrToInt(CellText) of
          1:
          begin
            CellText := '中国'
            sg.Canvas.TextRect(Rect, Rect.Left, Rect.Top, CellText) ;
          end;
          2:
          begin
            CellText := '美国'
            sg.Canvas.TextRect(Rect, Rect.Left, Rect.Top, CellText) ;
          end;
        end;
      end;
    end;
      

  5.   

    也可以在sql语句中转
    select 
    case
     when   job_id  = '1' then  '中国'
     when   job_id  =' 2' then  '美国'  
    end 
    from jobs
      

  6.   

    DBGridEh.Columns[0].PickList := '中国'#13'美国';
    DBGridEh.Columns[0].KeyList := '1'#13'2';
      

  7.   

    DBGridEh直接可以设置呀!双击DBGridEh,选中其中一个字段
    有属性PickList与KeyListPickList设置你要显示的,如"中国",“美国”....
    KeyList为你字段可能出现的所有的值,如"1","2"......注意,次序要对应一致
      

  8.   

    meiqingsong(阿飛):
    这个好像只可以SQL Server中吧?我在ADO连Access中好像出错!!
      

  9.   

    SQL Server 和 mysql中可以
      

  10.   

    用picklist和keylist
    picklist 里存的是要显示出来的如“中国”
    keylist  李存的是值 如 1
    两边的东西是顺序对应的!!
      

  11.   

    keylist 是与你的表中的字段对应的。如果keylist中没有,就按原值显示!!
      

  12.   

    我的贴子http://community.csdn.net/Expert/topic/3072/3072716.xml?temp=.2834741
    这里也有提到!
      

  13.   

    改sql语句
     select '中国'=1,'美国'=2 from table
      

  14.   

    两种方法如果DBGRID是动态的可以在SQL中改
    select 1 AS 中国,2 AS 美国 from table
    如果BDGRID是提前设置好的,把DBGRID得
    DBGrid1.Columns[0].Title:='中国'就可以了。
      

  15.   

    sql server数据库(最
    select 
            区域名=( case id when '1' then '中国'
                     when '2' then '美国'
                     end)
    from 表
    ========================