CXGRID的单元格如何实现自动计算? 本帖最后由 u012151930 于 2013-09-17 01:14:23 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的cxgrid应该有: 单价, 数量, 折扣, 金额这几列;如果是连着数据集的, 可以通过设定query计算列实现也可以自己写公式计算金额;//tv1: TcxGridBandedTableView;procedure TForm1.tv1EditValueChanged(Sender: TcxCustomGridTableView; AItem: TcxCustomGridTableItem);var dPrice, dQuantity, dCoupon : double;begin tv1.DataController.Post(); with tv1 do begin //金额计算 如果编辑单价, 数量, 优惠, 则计算消费金额 if Controller.FocusedColumnIndex in [clmPrice.Index, clmQuantity.Index, clmCoupon.Index] then begin dPrice := DataController.Values[Controller.FocusedRecordIndex, clmPrice.index]; dQuantity := DataController.Values[Controller.FocusedRecordIndex, clmQuantity.index]; dCoupon := DataController.Values[Controller.FocusedRecordIndex, clmCoupon.index]; DataController.Values[Controller.FocusedRecordIndex, clmTotal.index] := dPrice * dCoupon / 10 * dQuantity; end; end;end;上边的代码没有做异常处理, lz可以设置列属性为货币型, 并对数值有效性做处理.合计可以通过对金额列页脚求和实现 请问这两段代码是什么意思?谢谢你了。tv1.DataController.Post();if Controller.FocusedColumnIndex in [clmPrice.Index, clmQuantity.Index, clmCoupon.Index] then tv1.DataController.Post();//提交数据, 因为在此事件中, 你编辑的数据并未存入控件//如果编辑的是单价, 数量, 折扣时计算金额 clmPrice.Index, clmQuantity.Index, clmCoupon.Index 分别为对应列的下标 if Controller.FocusedColumnIndex in [clmPrice.Index, clmQuantity.Index, clmCoupon.Index] then tv1.DataController.Post() 请问POST后面的()是什么作用?不加()有什么不同? DataController.Values[Controller.FocusedRecordIndex, clmTotal.index] 这条语句是什么意思? tv1.DataController.Post() DataController.Values[Controller.FocusedRecordIndex, clmTotal.index] 这都是基础知识, 你看源码就能解答.tv1.DataController.Post(); //参数为是否强制提交的选项, 因为有默认值, 括号可以省略tv1.DataController.Post; <==> tv1.DataController.Post();DataController.Values[Controller.FocusedRecordIndex, clmTotal.index] 获取当前单元格的数值 求助:delphi代码中创建一个对象,怎么获取这个对象事件中的变量值 如何判断某个组件是否属于容器类? delphi断点错位,如何解决? 修改数据这样对吗 关于改变treeview 某些节点文本颜色的问题~~~帮帮忙 请问:谁有Delphi 5.x分布式多层应用电子商务篇的下载地址, pdf格式 我是一个delphi新手,想问一个问题 SOCKET通信,服务程序 谁能解我心中疑问 如何动态修改BDE配置????? 请各位推荐个DELPHI 免费界面库 谢谢 求 非EXE后缀的文件 以EXE执行文件方式运行方法
如果是连着数据集的, 可以通过设定query计算列实现
也可以自己写公式计算金额;
//tv1: TcxGridBandedTableView;
procedure TForm1.tv1EditValueChanged(Sender: TcxCustomGridTableView;
AItem: TcxCustomGridTableItem);
var
dPrice, dQuantity, dCoupon : double;
begin
tv1.DataController.Post();
with tv1 do
begin
//金额计算 如果编辑单价, 数量, 优惠, 则计算消费金额
if Controller.FocusedColumnIndex in [clmPrice.Index, clmQuantity.Index, clmCoupon.Index] then
begin
dPrice := DataController.Values[Controller.FocusedRecordIndex, clmPrice.index];
dQuantity := DataController.Values[Controller.FocusedRecordIndex, clmQuantity.index];
dCoupon := DataController.Values[Controller.FocusedRecordIndex, clmCoupon.index]; DataController.Values[Controller.FocusedRecordIndex, clmTotal.index] :=
dPrice * dCoupon / 10 * dQuantity;
end;
end;
end;上边的代码没有做异常处理, lz可以设置列属性为货币型, 并对数值有效性做处理.合计可以通过对金额列页脚求和实现
请问这两段代码是什么意思?谢谢你了。
tv1.DataController.Post();
if Controller.FocusedColumnIndex in [clmPrice.Index, clmQuantity.Index, clmCoupon.Index] then
if Controller.FocusedColumnIndex in [clmPrice.Index, clmQuantity.Index, clmCoupon.Index] then
tv1.DataController.Post() 请问POST后面的()是什么作用?不加()有什么不同?
DataController.Values[Controller.FocusedRecordIndex, clmTotal.index] 这都是基础知识, 你看源码就能解答.tv1.DataController.Post(); //参数为是否强制提交的选项, 因为有默认值, 括号可以省略
tv1.DataController.Post; <==> tv1.DataController.Post();
DataController.Values[Controller.FocusedRecordIndex, clmTotal.index]
获取当前单元格的数值