在动态添加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;

转载于:https://www.cnblogs.com/railgunman/archive/2011/01/02/1924110.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以在 RecyclerView 中添加头部和尾部视图来实现添加 header 和 footer 的效果。下面是一种常见的实现方式: 首先,你需要创建两个布局文件用作 header 和 footer 的视图。例如,header_view.xml 和 footer_view.xml。 然后,在你的 RecyclerView 的适配器中,你需要创建两个常量来表示 header 和 footer 的视图类型。例如,HEADER_VIEW_TYPE 和 FOOTER_VIEW_TYPE。 接下来,在适配器中,你需要重写以下几个方法: 1. getItemViewType(int position) 方法:根据 position 来返回相应的视图类型。如果 position 是 0,则返回 HEADER_VIEW_TYPE;如果 position 是数据集合的大小加上 1,则返回 FOOTER_VIEW_TYPE;否则返回普通的 item 类型。 2. onCreateViewHolder(ViewGroup parent, int viewType) 方法:根据 viewType 来创建对应的 ViewHolder。如果 viewType 是 HEADER_VIEW_TYPE 或 FOOTER_VIEW_TYPE,则使用相应的布局文件创建 ViewHolder;否则使用普通的 item 布局文件创建 ViewHolder。 3. onBindViewHolder(ViewHolder holder, int position) 方法:根据 position 来绑定数据到 ViewHolder。如果 position 是 HEADER_VIEW_TYPE 或 FOOTER_VIEW_TYPE,则不需要绑定数据;否则绑定普通的 item 数据。 最后,在你的 RecyclerView 中设置适配器,并在数据集合中添加对应的数据项作为 header 和 footer。例如,使用以下代码: ``` MyAdapter adapter = new MyAdapter(dataList); adapter.addHeader(headerData); adapter.addFooter(footerData); recyclerView.setAdapter(adapter); ``` 请注意,上述代码中的 MyAdapter 是你自定义的 RecyclerView.Adapter 子类,其中包含了添加 header 和 footer 的方法。 以上就是在 RecyclerView 中添加 header 和 footer 的基本步骤。希望能对你有所帮助!如有需要,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值