我想显示一个数据表内容列表,其中某个字段为0/1, 想显示为成功/失败,
请问用什么控件?用dbgrid可以吗?

解决方案 »

  1.   

    使用sql语句直接变换select case 字段 when 0 then ‘成功’when 1 then ‘失败’end as 字段 from 表
      

  2.   

    1、设计时,设置DBGrid的DefaultDrawing  :=  False(缺省为True)  
     
    2、响应DBGrid的OnDrawColumnCell事件:  
    procedure  TForm1.DBGrid1DrawColumnCell(Sender:  TObject;  const  Rect:  TRect;  
       DataCol:  Integer;  Column:  TColumn;  State:  TGridDrawState);  
    var  
       OutputStr:  string;  
    begin  
       //假设该DBGrid与Query1相关联  
       if  Query1.IsEmpty  then  
       begin  
           DBGrid1.DefaultDrawColumnCell(Rect,  DataCol,  Column,  State);  
           Exit;  
       end;  
     
       //假设onguard字段是Query1查询结果记录的第一个字段  
       case  DataCol  of  
           0:  
               begin  
                   if  Column.Field.AsInteger  =  0  then  
                       OutputStr  :=  '成功'
                   else  
                       OutputStr  :=  '失败';  
                   DBGrid1.Canvas.TextRect(Rect,  Rect.Left  +  2,  Rect.Top  +  2,  OutputStr);  
               end;  
       else  
           DBGrid1.DefaultDrawColumnCell(Rect,  DataCol,  Column,  State);  
       end;  
    end;  
      

  3.   

    不知你用的是什么库
    在oracle中:select decode(字段,'1','失败','0','成功') 字段别名 from 表名