FastReport.Net:如何动态地在ReportSummaryBand中添加Total

时间:2017-09-28 07:18:57

标签: c# fastreport

我已经编写了这部分代码来添加字段摘要" Count"报告摘要带:

Total colTotal = CreateTotal();
colTotal.SetReport(report);
colTotal.PrintOn = reportSummaryBand;                
TextObject colTitle = new TextObject();
colTitle.Text="[" + colTotal.Name + "]";
reportSummaryBand.Objects.Add(colTitle);

CreateTotal函数如下:

private Total CreateTotal()
{
    Total colTotal = new Total();
    colTotal.TotalType = TotalType.SUM, 
    columnHeader.Agg_Func_Type.ToString());
    colTotal.SetName("CountTotal");
    colTotal.Expression = "[MyTable.Count]";
    return colTotal;
}

但我收到错误:   错误CS0103:名称' CountTotal'在当前上下文中不存在

1 个答案:

答案 0 :(得分:0)

通过将以下更改应用于CreateTotal函数问题得以解决。希望能帮助到你 : 感谢Dmitriy Fedyashov为此链接:https://www.fast-report.com/en/blog/68/show/

  private Total CreateTotal(Report report, DataBand dataBand, ReportSummaryBand repSumBand, ColumnHeader columnHeader)
    {
        // create total
        Total colTotal = new Total();
        colTotal.SetName("CountTotal");
        colTotal.Expression = "[MyTable.Count]";
        colTotal.Evaluator = dataBand;
        colTotal.PrintOn = repSumBand;
        colTotal.TotalType = TotalType.Sum;                  

        report.Dictionary.Totals.Add(colTotal);
        return colTotal;
    }