cxGrid的话还容易.还一个方法是数据库处理 select 金额+'元' as 金额 from table
1.每行都加“元”不好, 不如在标题栏内加“元”; 2.可以用 select (金额)+'元' as 金额 from table (需要将金额字段类型转换为字符串)
... ADoDataSet.Open; ADODataSet1.FieldByName('你的字段').OnGetText:=uGetValueText;procedure uGetValueText(Sender: TField; var Text: string; DisplayText: Boolean); begin if Sender.IsNull then Exit; Text:=Sender.AsString+'元'; end;
2.可以用 select (金额)+'元' as 金额 from table (需要将金额字段类型转换为字符串)
ADoDataSet.Open;
ADODataSet1.FieldByName('你的字段').OnGetText:=uGetValueText;procedure uGetValueText(Sender: TField; var Text: string; DisplayText: Boolean);
begin
if Sender.IsNull then Exit;
Text:=Sender.AsString+'元';
end;
text:=format('%m元',[sender.AsCurrency])
unit MainFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, DB, ADODB, ComCtrls;
type
TMainForm = class(TForm)
......
procedure Button1Click(Sender: TObject);
private
procedure uGetValueText(Sender: TField; var Text: string; DisplayText: Boolean);
end;
var
MainForm: TMainForm;
implementation
procedure
procedure TMainForm.Button1Click(Sender: TObject);
var
AdoDt:TADODataSet;//AdoQuery也一样
begin
//查询数据我就不写了,自己处理这部分我写后面的
ADoDt.Open();
ADoDt.FieldByName('金额').OnGetText:=uGetValueText;
end;
procedure TMainForm.uGetValueText(Sender: TField; var Text: string; DisplayText:
Boolean);
begin
if Sender.IsNull then Exit;
Text:=Sender.AsString+'元'
end;
end;