zoukankan      html  css  js  c++  java
  • 在动态添加Footer SummaryItem和Group的Item

    http://www.delphibbs.com/delphibbs/dispq.asp?lid=2135268

    ////////////////////////////////////////////////
    with tvOrders.DataController.Summary do
      begin
        BeginUpdate;
        try
          with FooterSummaryItems.Add as TcxGridDBTableSummaryItem do
          begin
            Column := tvOrdersPaymentAmount;
            Kind := skSum;
            Format := 'SUM = $,0.00;-$,0.00';
          end;
        finally
          EndUpdate;
        end;
        //Update all open details of the master view (tvCars)
        tvCars.DataController.ClearDetails;
      end;
    //////////////////////////////
    以上是TcxGridDBTableSummaryItem
    但是我在tcxgriddbbandedtableview 中没有反应不显示??
    、、、、、、、、、、、、、、、、、、
    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;
    、、、、、、、、、、、、、、、、、、、、、、、、、
    group的也一样!
    根据如下创建的字段 没有名字
    With cxgrid1dbbandedtableview1.CreateColumn do
        begin
         Caption :='月%';
         DataBinding.FieldName:='zpmp' ;
         Position.BandIndex := 4;
         Position.RowIndex := 0;
         //Position.LineCount:=1;
         Visible := True;
    showmessage(cxgrid1dbbandedtableview1.CreateColumn.Name);、、、
          end;
    从而引起了以上的错误,我想,不知道有没有高手帮忙


    从帮助中看到两个例子:、、
    、、、、、、、、、、、、、、
    procedure TForm1.cxGrid1DBTableView1TcxGridDBDataControllerTcxDataSummary
    DefaultGroupSummaryItemsSummary(
      ASender: TcxDataSummaryItems; Arguments: TcxSummaryEventArguments;
      var OutArguments: TcxSummaryEventOutArguments);
    begin
      if (VarIsNull(OutArguments.Value)) then
        OutArguments.Done := True;
    end;
    /////////////////////
    //Delphi
    procedure TForm1.cxGrid1DBTableView1TcxGridDBDataControllerTcxDataSummary
    DefaultGroupSummaryItemsSummary(
      ASender: TcxDataSummaryItems; Arguments: TcxSummaryEventArguments;
      var OutArguments: TcxSummaryEventOutArguments);
    var
      AArea, APopulation: Extended;
    begin
      //Locate a value in the specific record for Area item
      AArea := ASender.DataController.Values[Arguments.RecordIndex, DBTableView1Area.Index];
      //Locate a value in the specific record for Population item
      APopulation := ASender.DataController.Values[Arguments.RecordIndex, DBTableView1Population.Index];
      //Set population density to Value
      OutArguments.Value := APopulation / AArea;
    end;
    不知道如何取得另一字段的foooter 和更改这一字段的footer 


    发现一个example
    、、、、、、、、、、、、、、、、、、、
    In this example, a summary value is calculated based on the results of other two summaries.  The TcxDataSummary.OnAfterSummary event, which occurs when all summaries are already calculated, is used to calculate a new summary.
    Let us examine a table that represents information from the pricelist containing three columns: VendorNo, Description, ListPrice.  We want to group data by vendor and calculate three summaries: the summary that displays a sum of the ListPrice column values, the summary representing the number of goods supplied by a specific vendor and the summary that displays the average value of the ListPrice column values.  Though it is possible to create an average summary by specifying its skAverage type, we will calculate it based on two other summary values and format it in a specific manner.  
    The Initialize procedure groups data by vendor and creates three summaries.  The third summary is of the skNone type.  It is substituted for the average summary in MyAfterSummary (the OnAfterSummary event handler).
    //Delphi
    procedure TForm1.Initialize;
    var
      ASummaryItem: TcxDataSummaryItem;
    begin
      //group by vendor
      DBTableView1VendorNo.GroupIndex := 0;
      DBTableView1VendorNo.Visible := False;
      with DBTableView1.DataController.Summary do
      begin
        BeginUpdate;
        try
          //set prefix and postfix for a group capion
          DefaultGroupSummaryItems.BeginText := '{';
          DefaultGroupSummaryItems.EndText := '}';
          //summary on ListPrice
          ASummaryItem := DefaultGroupSummaryItems.Add;
          ASummaryItem.Kind := skSum;
          ASummaryItem.ItemLink := DBTableView1ListPrice;
          ASummaryItem.Position := spFooter;
          //summary on Description
          ASummaryItem := DefaultGroupSummaryItems.Add;
          ASummaryItem.Kind := skCount;
          ASummaryItem.ItemLink := DBTableView1Description;
          ASummaryItem.Position := spFooter;
          //dummy summary on Description
          ASummaryItem := DefaultGroupSummaryItems.Add;
          ASummaryItem.Kind := skNone;
          ASummaryItem.ItemLink := DBTableView1Description;
          //subscribe to the OnAfterSummary event
          OnAfterSummary := MyAfterSummary;
        finally
          EndUpdate;
        end;
      end;
    end;
    procedure TForm1.MyAfterSummary(ASender: TcxDataSummary);
    var
      AChildDataGroupsCount: Integer;
      AChildDataGroupIndex, AParentDataGroupIndex: TcxDataGroupIndex;
      AChildPosition: Integer;
    begin
      //iterate through data groups at the level 0
      AParentDataGroupIndex := -1;
      with DBTableView1.DataController.Groups do
      begin
        AChildDataGroupsCount := ChildCount[AParentDataGroupIndex];
        for AChildPosition := 0 to AChildDataGroupsCount - 1 do
        begin
          //data group index of a child
          AChildDataGroupIndex := ChildDataGroupIndex[AParentDataGroupIndex, AChildPosition];
          CalculateGroupAverage(AChildDataGroupIndex);
        end;
      end;
    end;
    procedure TForm1.CalculateGroupAverage(ADataGroupIndex: TcxDataGroupIndex);
    var
      AVarSum, AVarCount, AVarAverage: Variant;
    begin
      with DBTableView1.DataController.Summary do
      begin
        //get sum of prices for specific data group
        //the second argument identifies a summary index in the
        //TcxDataSummary.DefaultGroupSummaryItems collection
        AVarSum := GroupSummaryValues[ADataGroupIndex, 0];
        //get records count in a group
        AVarCount := GroupSummaryValues[ADataGroupIndex, 1];
        if not (VarIsNull(AVarSum) or VarIsNull(AVarCount)) then
        begin
          AVarAverage := AVarSum / AVarCount;
          GroupSummaryValues[ADataGroupIndex, 2] := Format('%m / %d = %m', [Double(AVarSum), Integer(AVarCount), Double(AVarAverage)]);
        end;
      end;
    end;

  • 相关阅读:
    Delphi 日期函数的单元 DateUtils
    学习官方示例 SysUtils.DecodeDate、DecodeTime
    msp430的常量可以这样定义
    学习官方示例 SysUtils.EncodeDate、EncodeTime、StrToDate、StrToTime、StrToDateTime
    Delphi中Format与FormatDateTime函数详解
    csdn太慢了搬到园子里来
    .net 2.0 真的能与1.1 安全正确地运行在同一台电脑上吗?
    照着这些做,生活自然很开心
    【转】SQL中取当前记录的ID>SCOPE_IDENTITY()
    [转]Windows XP Service Pack 2中弹出窗口拦截器的研究
  • 原文地址:https://www.cnblogs.com/railgunman/p/1924110.html
Copyright © 2011-2022 走看看