cxgrid 数据显示格式 大家好! 在cxgrid 中,如何在同一列显示数字和百分号。 请见下图: 如上图所示。数量栏位可以显示数字及百分号!谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 procedure TForm1.cxGrid1DBTableView1Column2GetDisplayText( Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord; var AText: String);//“数量”列取显示文本begin if pos('率', cxGrid1DBTableView1.DataController.Values[ARecord.Index,0])>0 then//如果当前记录中的“项目”列中有“率”字 AText:=Sender.EditValue+'%';//在当前列的值后面附加“%”符号end; gzzai 您好! 因为列是在程序中动态生成的。如何在动态的列中加入此行代码呢? gzzai 您好! 列是动态生成的。代码如下:var sSQL: string; i,j: Integer; cl: TcxGridDBBandEdColumn; cb:TcxGridBand; wk:string; vDate:string;begin inherited; self.CompanyName.Caption := PrintCompanyName; self.Title.Caption := PrintTitle; sSQL:= PrintSql; try Qryprint.DisableControls; if not Assigned(frmShowMsg) then frmShowMsg := TfrmShowMsg.Create(Application); frmShowMsg.Show; frmShowMsg.Update; Qryprint.Connection := DllAdoCn; dlladocn.CommandTimeout :=500; Qryprint.Close; Qryprint.SQL.Clear; Qryprint.SQL.Add(sSQL); Qryprint.Open; Screen.Cursor:=crHourGlass; cxGrid1DBBandedTableView1.BeginUpdate; wk:=''; j:=0; try for i:=3 to cxGrid1DBBandedTableView1.DataController.DataSet.FieldCount-1 do begin vDate:=cxGrid1DBBandedTableView1.DataController.DataSet.Fields[i].FieldName; if vDate <>'合计' then begin vDate :=COPY(vDate,1,4)+'-'+COPY(vDate,5,2)+'-'+COPY(vDate,7,2); if wk<> ('W'+IntToStr(WeekOf(StrToDate(vDate)))) then begin cb:=cxGrid1DBBandedTableView1.Bands.Add; cb.Caption :=('W'+IntToStr(WeekOf(StrToDate(vDate)))); cl:=cxGrid1DBBandedTableView1.CreateColumn; cl.DataBinding.FieldName:=cxGrid1DBBandedTableView1.DataController.DataSet.Fields[i].FieldName; cl.Caption :=copy(vDate,6,5); cl.HeaderAlignmentHorz :=taCenter; cl.HeaderAlignmentVert :=vaCenter; cl.Position.BandIndex :=j+1; wk :='W'+IntToStr(WeekOf(StrToDate(vDate))); j:=j+1; end else begin cl:=cxGrid1DBBandedTableView1.CreateColumn; cl.DataBinding.FieldName:=cxGrid1DBBandedTableView1.DataController.DataSet.Fields[i].FieldName; cl.Caption :=copy(vDate,6,5); cl.HeaderAlignmentHorz :=taCenter; cl.HeaderAlignmentVert :=vaCenter; cl.Position.BandIndex :=j; end; end else begin cb:=cxGrid1DBBandedTableView1.Bands.Add; cb.Caption :=''; cl:=cxGrid1DBBandedTableView1.CreateColumn; cl.DataBinding.FieldName:=cxGrid1DBBandedTableView1.DataController.DataSet.Fields[i].FieldName; cl.HeaderAlignmentHorz :=taCenter; cl.HeaderAlignmentVert :=vaCenter; cl.Position.BandIndex :=j+1; j:=j+1; end; end; finally cxGrid1DBBandedTableView1.EndUpdate; end; finally Qryprint.EnableControls; frmShowMsg.Close; frmShowMsg.Free; Screen.Cursor:=crDefault; end;end;如何在新生成的列中添加GetDisplayText事件呢!谢谢! 用SQL在后台生成你要的数据,必要时用CAST强制转换即可。 一个相当简单的问题! 如何在DLL中建立窗体? 在窗体创建时如何在combobox下拉单里加载数据库字段~~新手急等,送高分。 如何调用其它的Windows应用程序,比如文本编辑器 如何判断鼠标按下的是哪个键! 如何编译成单独的可执行文件???非常急!!! treeview中如何设定每个item的字体?(有不同) 如何检测在DBGIRD中输入数据的正确性? 各位大侠,请教reset()打开文件的问题。 谁有文档加密方面的源码(就是只能在本机打开,文档拷贝到其它机器打不开),想购买... 判读窗体指针问题 在线求助
Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
var AText: String);//“数量”列取显示文本
begin
if pos('率', cxGrid1DBTableView1.DataController.Values[ARecord.Index,0])>0 then//如果当前记录中的“项目”列中有“率”字
AText:=Sender.EditValue+'%';//在当前列的值后面附加“%”符号
end;
您好!
因为列是在程序中动态生成的。如何在动态的列中加入此行代码呢?
您好!
列是动态生成的。代码如下:
var
sSQL: string;
i,j: Integer;
cl: TcxGridDBBandEdColumn;
cb:TcxGridBand;
wk:string;
vDate:string;
begin
inherited;
self.CompanyName.Caption := PrintCompanyName;
self.Title.Caption := PrintTitle;
sSQL:= PrintSql;
try
Qryprint.DisableControls;
if not Assigned(frmShowMsg) then
frmShowMsg := TfrmShowMsg.Create(Application);
frmShowMsg.Show;
frmShowMsg.Update;
Qryprint.Connection := DllAdoCn;
dlladocn.CommandTimeout :=500;
Qryprint.Close;
Qryprint.SQL.Clear;
Qryprint.SQL.Add(sSQL);
Qryprint.Open;
Screen.Cursor:=crHourGlass;
cxGrid1DBBandedTableView1.BeginUpdate;
wk:='';
j:=0;
try
for i:=3 to cxGrid1DBBandedTableView1.DataController.DataSet.FieldCount-1 do
begin
vDate:=cxGrid1DBBandedTableView1.DataController.DataSet.Fields[i].FieldName;
if vDate <>'合计' then
begin
vDate :=COPY(vDate,1,4)+'-'+COPY(vDate,5,2)+'-'+COPY(vDate,7,2);
if wk<> ('W'+IntToStr(WeekOf(StrToDate(vDate)))) then
begin
cb:=cxGrid1DBBandedTableView1.Bands.Add;
cb.Caption :=('W'+IntToStr(WeekOf(StrToDate(vDate))));
cl:=cxGrid1DBBandedTableView1.CreateColumn;
cl.DataBinding.FieldName:=cxGrid1DBBandedTableView1.DataController.DataSet.Fields[i].FieldName;
cl.Caption :=copy(vDate,6,5);
cl.HeaderAlignmentHorz :=taCenter;
cl.HeaderAlignmentVert :=vaCenter;
cl.Position.BandIndex :=j+1;
wk :='W'+IntToStr(WeekOf(StrToDate(vDate)));
j:=j+1;
end
else
begin
cl:=cxGrid1DBBandedTableView1.CreateColumn;
cl.DataBinding.FieldName:=cxGrid1DBBandedTableView1.DataController.DataSet.Fields[i].FieldName;
cl.Caption :=copy(vDate,6,5);
cl.HeaderAlignmentHorz :=taCenter;
cl.HeaderAlignmentVert :=vaCenter;
cl.Position.BandIndex :=j;
end;
end
else
begin
cb:=cxGrid1DBBandedTableView1.Bands.Add;
cb.Caption :='';
cl:=cxGrid1DBBandedTableView1.CreateColumn;
cl.DataBinding.FieldName:=cxGrid1DBBandedTableView1.DataController.DataSet.Fields[i].FieldName;
cl.HeaderAlignmentHorz :=taCenter;
cl.HeaderAlignmentVert :=vaCenter;
cl.Position.BandIndex :=j+1;
j:=j+1;
end;
end;
finally
cxGrid1DBBandedTableView1.EndUpdate;
end;
finally
Qryprint.EnableControls;
frmShowMsg.Close;
frmShowMsg.Free;
Screen.Cursor:=crDefault;
end;
end;如何在新生成的列中添加GetDisplayText事件呢!
谢谢!