cxgrid 数据显示格式

maoyunaa 2012-11-20 09:01:58
大家好!
在cxgrid 中,如何在同一列显示数字和百分号。
请见下图:

如上图所示。数量栏位可以显示数字及百分号!

谢谢!
...全文
407 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
kye_jufei 2012-11-23
  • 打赏
  • 举报
回复
用SQL在后台生成你要的数据,必要时用CAST强制转换即可。
maoyunaa 2012-11-21
  • 打赏
  • 举报
回复
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事件呢! 谢谢!
maoyunaa 2012-11-21
  • 打赏
  • 举报
回复
gzzai 您好! 因为列是在程序中动态生成的。如何在动态的列中加入此行代码呢?
tgbd 2012-11-21
  • 打赏
  • 举报
回复
建议楼主要后台处理更方便。从数据源中生成。
广州佬 2012-11-20
  • 打赏
  • 举报
回复
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;

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧