数据库中的财务表为:
  ID  收支类型  金额  其它属性其中收支类型只有两种值:0 表示收入,1 表示支出 ;金额都是正数。设置cxGrid的Footer 可以使得在显示时,列表的下方出现汇总行:“金额”的和
同样设置Default For Groups可以使得在用户拖动表头属性实现分组时,显示组内的汇总行:“金额”的和。上面说的,用过cxGrid应该都会,下面就有这么一个问题如果我想使汇总行的值变为如下的值应该怎样实现:
       收支类型为0的金额的和 - 收支类型为1的金额的和
实现Footer的功能好办,因为它的值不会变,自己用循环写一个就完了,但是Default For Groups的功能就不好说了,因为它的值是根据用户拖动的属性计算的,而且还有可能是多层分组,想不出来了,所有到这来问
是不是要设置什么属性?或者cxGrid根本就没这个功能,那该用什么方法解决?希望哪位帮我解决,谢谢了先!

解决方案 »

  1.   

    up up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up upup up up
      

  2.   

    给你一个例子,可能对你有帮助,
     with tvOrders.DataController.Summary do  begin
        BeginUpdate;
        try
          SummaryGroups.Clear;
          //The first summary group
          with SummaryGroups.Add do
          begin
            //Add proposed grouping column(s)
            TcxGridTableSummaryGroupItemLink(Links.Add).Column := tvOrdersCustomerID;
            //Add summary items
            with SummaryItems.Add as TcxGridDBTableSummaryItem do
            begin
              Column := tvOrdersPaymentAmount;
              Kind := skSum;
              Format := 'Amount Paid: $,0';
            end;        with SummaryItems.Add as TcxGridDBTableSummaryItem do
            begin
              Column := tvOrdersPaymentAmount;
              Kind := skCount;
              Format := 'Records: 0';
            end;      end;      //The second summary group
          with SummaryGroups.Add do
          begin
            //Add proposed grouping column(s)
            TcxGridTableSummaryGroupItemLink(Links.Add).Column := tvOrdersProductID;
            //Add summary items
            with SummaryItems.Add as TcxGridDBTableSummaryItem do
            begin
              Column := tvOrdersQuantity;
              Kind := skSum;
              Position := spFooter;
              Format := 'TOTAL = 0';
            end;        with SummaryItems.Add as TcxGridDBTableSummaryItem do
            begin
              Column := tvOrdersPurchaseDate;
              Kind := skMin;
              Position := spFooter;
            end;
          end;    finally
          EndUpdate;
        end;
      end;
      

  3.   

    这个问题的本质在于cxGrid分组合计功能类似SQL:
    select sum(金额) from xxx group by xxx
    既然你的金额都是不分正负的,当然结果是累加不会减的。要么就将支出方置为负数,要么将金额 select成两列. 这两个方法我现在都用。
    cxGrid我用得算是有点熟了,你说的我很理解,你想在Default For Groups想分出正负来减,是没有这样现成的功能的.
      

  4.   

    控件叫:DevExpress QuantumGrid 4.5,www.51delphi.com上就有,各位帮忙看看。
    我试试 XRS(心如水) 的方法先。
      

  5.   

    to XRS(心如水) 
    将支出方置为负数的已经实现了。
    将金额 select成两列的怎样实现的?把SQL语句贴出来一下,谢谢了!
      

  6.   

    select ID,
    case when 收支类型=0 then 金额 end as 收入金额,
    case when 收支类型=1 then 金额 end as 支出金额,
    .
    .
    from xxx where xxx
      

  7.   

    为什么我用If会出错:
    SELECT ID, 收支类型, IF 收支类型 = 0 THEN 金额 AS 收入金额, 
          IF 收支类型 = 1 THEN 金额 AS 支出金额
    FROM 财务表
      

  8.   

    select 语句里不能用if 判断,用case代替