PrintDocument for WinForms | ComponentOne
PrintDocument Library / Aggregates
In This Topic
    Aggregates
    In This Topic

    Aggregate types can be used in data-bound PrintDocument without the need to declare them in the document's aggregates collection (Aggregates).

    For instance, if "Balance" is a data field in a data-bound document, the following RenderText can be used to print the total balance for the dataset:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim rt As New RenderText("[Sum(""Fields!Balance.Value"")]")
    

    To write code in C#

    C#
    Copy Code
    RenderText rt = new RenderText("[Sum(\"Fields!Balance.Value\")]");
    

    The following new properties and methods were added to the DataSet and C1DataBinding types to support this feature:

    Class Member Description
    C1DataBinding Name property Gets or sets the name of the current C1DataBinding. That name can be used in aggregate functions to indicate which data binding the aggregate refers to.
    DataSet Name property Gets or sets the name of the current DataSet. That name can be used in aggregate functions to indicate which data set the aggregate refers to.

    All aggregate functions have the following format:

    AggFunc(expression, scope)

    where:

    For example, if a dataset has the following fields, ID, GroupID, SubGroupID, NAME, Q, and records are grouped by GroupID and SubGroupID, the following document can be created:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim doc As New C1PrintDocument()
    Dim raGroupId As New RenderArea()
    ' set up raGroupId properties as desired...
    raGroupID.DataBinding.DataSource = dataSet
    raGroupID.DataBinding.Name = "GroupID"
    raGroupID.DataBinding.Grouping.Expressions.Add("Fields!GroupID.Value")
     
    Dim raSubGroupID As New RenderArea()
    ' set up raSubGroupID properties as desired...
    raSubGroupID.DataBinding.DataSource = dataSet
    raSubGroupID.DataBinding.Grouping.Expressions.Add("Fields!SubGroupID.Value")
    raGroupID.Children.Add(raSubGroupID)
     
    Dim raDetail As New RenderArea()
    ' set up raDetail properties as desired...
    raDetail.DataBinding.DataSource = dataSet
    raSubGroupID.Children.Add(raDetail)
     
    ' show value of Q field:
    Dim rtQ As New RenderText()
    rtQ.Text = "[Fields!Q.Value]"
    raDetail.Children.Add(rtQ)
     
    ' show sum of Q field for nested group (SubGroupID):
    Dim rtSumQ1 As New RenderText()
    rtSumQ1.Text = "[Sum(""Fields!Q.Value"")]"
    raDetail.Children.Add(rtSumQ1)
    ' show sum of Q field for GroupID:
    Dim rtSumQ2 As New RenderText()
    rtSumQ2.Text = "[Sum(\"Fields!Q.Value\", "\"GroupID\"")]"
    raDetail.Children.Add(rtSumQ2)
    ' show TOTAL sum of Q field for the entire dataset:
    Dim rtSumQ3 As New RenderText()
    rtSumQ3.Text = "[Sum(\"Fields!Q.Value\", "\"DataSet\"")]"
    raDetail.Children.Add(rtSumQ3)
    doc.Body.Children.Add(raGroupId)
    

    To write code in C#

    C#
    Copy Code
    C1PrintDocument doc = new C1PrintDocument();
    RenderArea raGroupId = new RenderArea();
    // set up raGroupId properties as desired...
    raGroupID.DataBinding.DataSource = dataSet;
    raGroupID.DataBinding.Name = "GroupID";
    raGroupID.DataBinding.Grouping.Expressions.Add("Fields!GroupID.Value");
     
    RenderArea raSubGroupID = new RenderArea();
    // set up raSubGroupID properties as desired...
    raSubGroupID.DataBinding.DataSource = dataSet;
    raSubGroupID.DataBinding.Grouping.Expressions.Add("Fields!SubGroupID.Value");
    raGroupID.Children.Add(raSubGroupID);
     
    RenderArea raDetail = new RenderArea();
    // set up raDetail properties as desired...
    raDetail.DataBinding.DataSource = dataSet;
    raSubGroupID.Children.Add(raDetail);
     
    // show value of Q field:
    RenderText rtQ = new RenderText();
    rtQ.Text = "[Fields!Q.Value]";
    raDetail.Children.Add(rtQ);
    // show sum of Q field for nested group (SubGroupID):
    RenderText rtSumQ1 = new RenderText();
    rtSumQ1.Text = "[Sum(\"Fields!Q.Value\")]";
    raDetail.Children.Add(rtSumQ1);
    // show sum of Q field for GroupID:
    RenderText rtSumQ2 = new RenderText();
    rtSumQ2.Text = "[Sum(\"Fields!Q.Value\", "\"GroupID\"")]";
    raDetail.Children.Add(rtSumQ2);
    // show TOTAL sum of Q field for the entire dataset:
    RenderText rtSumQ3 = new RenderText();
    rtSumQ3.Text = "[Sum(\"Fields!Q.Value\", "\"DataSet\"")]";
    raDetail.Children.Add(rtSumQ3);
     
    doc.Body.Children.Add(raGroupId);
    

    When the above document is generated, each instance of the raDetail group will show four values as follows: