我想显示一个数据表内容列表,其中某个字段为0/1, 如何显示为成功/失败? 我想显示一个数据表内容列表,其中某个字段为0/1, 想显示为成功/失败,请问用什么控件?用dbgrid可以吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用sql语句直接变换select case 字段 when 0 then ‘成功’when 1 then ‘失败’end as 字段 from 表 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; 不知你用的是什么库在oracle中:select decode(字段,'1','失败','0','成功') 字段别名 from 表名 windows自带下载程序API,我要hook它, delphi调用AJAX的问题,急!高分在线等! 如何Delphi2007打开浏览工程文件? 呜呜,硬盘让我用坏了,进不了系统了 恭喜哈欠夫妇造人成功 能設置 TCPClient timeout的值嗎?? Missing operator or semicolon 请高手解释一下什么意思 是否可以不单独安装数据库的客户端 ado方面的,如果更新数据? 请进,一个关于数据库设计的问题!很简单,送分!在线等候 怎么新创建的窗口显示不出来?100分 很基础的问题
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;
在oracle中:select decode(字段,'1','失败','0','成功') 字段别名 from 表名