procedure TForm1.ADOQuery1IntFieldGetText(Sender: TField; var Text: String; DisplayText: Boolean); begin if TIntegerField(Sender).AsInteger =1 then begin Text:='中国'; end; end;
if ADOQuery1.FieldByName('attribute_id').AsString=inttostr(1) then DBGrid1.Columns[0].FieldName:='中国';
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;
也可以在sql语句中转 select case when job_id = '1' then '中国' when job_id =' 2' then '美国' end from jobs
DisplayText: Boolean);
begin
if TIntegerField(Sender).AsInteger =1 then
begin
Text:='中国';
end;
end;
DBGrid1.Columns[0].FieldName:='中国';
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;
select
case
when job_id = '1' then '中国'
when job_id =' 2' then '美国'
end
from jobs
DBGridEh.Columns[0].KeyList := '1'#13'2';
有属性PickList与KeyListPickList设置你要显示的,如"中国",“美国”....
KeyList为你字段可能出现的所有的值,如"1","2"......注意,次序要对应一致
这个好像只可以SQL Server中吧?我在ADO连Access中好像出错!!
picklist 里存的是要显示出来的如“中国”
keylist 李存的是值 如 1
两边的东西是顺序对应的!!
这里也有提到!
select '中国'=1,'美国'=2 from table
select 1 AS 中国,2 AS 美国 from table
如果BDGRID是提前设置好的,把DBGRID得
DBGrid1.Columns[0].Title:='中国'就可以了。
select
区域名=( case id when '1' then '中国'
when '2' then '美国'
end)
from 表
========================