本帖最后由 u012151930 于 2013-09-17 01:14:23 编辑

解决方案 »

  1.   

    你的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可以设置列属性为货币型, 并对数值有效性做处理.合计可以通过对金额列页脚求和实现
      

  2.   


    请问这两段代码是什么意思?谢谢你了。
    tv1.DataController.Post();
    if Controller.FocusedColumnIndex in [clmPrice.Index, clmQuantity.Index, clmCoupon.Index] then
      

  3.   

    tv1.DataController.Post();//提交数据, 因为在此事件中, 你编辑的数据并未存入控件//如果编辑的是单价, 数量, 折扣时计算金额 clmPrice.Index, clmQuantity.Index, clmCoupon.Index 分别为对应列的下标 
    if Controller.FocusedColumnIndex in [clmPrice.Index, clmQuantity.Index, clmCoupon.Index] then
      

  4.   


    tv1.DataController.Post()  请问POST后面的()是什么作用?不加()有什么不同?
      

  5.   

    DataController.Values[Controller.FocusedRecordIndex, clmTotal.index] 这条语句是什么意思?
      

  6.   

    tv1.DataController.Post() 
    DataController.Values[Controller.FocusedRecordIndex, clmTotal.index] 这都是基础知识, 你看源码就能解答.tv1.DataController.Post(); //参数为是否强制提交的选项, 因为有默认值, 括号可以省略
    tv1.DataController.Post;  <==> tv1.DataController.Post();
    DataController.Values[Controller.FocusedRecordIndex, clmTotal.index] 
    获取当前单元格的数值