ActiveReports 11
Calculated Fields
ActiveReports 11 > ActiveReports User Guide > Samples and Walkthroughs > Samples > Section Report > Summary > Calculated Fields

The CalculatedFields sample demonstrates the use of calculated fields in a report, where the field values are calculated in code. A custom field is added to the Fields collection in the DataInitialize event and the field value is calculated in the FetchData event.

Sample Location

Visual Basic.NET

<User Folder>\Documents\GrapeCity Samples\ActiveReports 11\Section Reports\Summary\CalculatedFields\VB.NET

C#

<User Folder>\Documents\GrapeCity Samples\ActiveReports 11\Section Reports\Summary\CalculatedFields\C#

Run-Time Features

When you run the sample, a report displaying ProductID, UnitPrice, Quantity, Discount, Extended Price and Total value for each OrderID is displayed in the Viewer control. The Extended Price value is a calculated field that displays the result of the formula specified in FetchData event.

Note: To run this sample, you must have access to the Nwind.mdb. A copy is located at [User Documents folder]\GrapeCity Samples\ActiveReports 11\Data\NWIND.mdb. If you are unable to access the data files in the sample, create the Data folder and place all the data files to this folder, or change the reference path to the data files within the folder according to your environment.

Project Details

StartForm

The Viewer control has the Dock property set to Fill. This ensures that the viewer resizes along with the form at run time. Right-click the form and select View Code to see the code used to run the report and display it in the viewer.

OrdersReport

The OrdersReport uses a GroupHeader section, a Detail section and a GroupFooter section as well as a Label in the PageFooter section to display data.

Note: Except for the Detail section, all sections come in header and footer pairs. Unused sections have their Height properties set to 0 and their Visible properties set to False.

ghOrderID section

This group header section has the DataField property set to OrderID. This setting, along with data sorted by the same field, displays a report grouped by OrderID. The section contains one bound TextBox control to display the OrderID at the beginning of each group.

Detail section

Detail section of this report contains 5 bound TextBox controls that render for each row of data of the OrderID.

gfOrderID section

This group footer section displays total of the gfOrderID data in TextBox controls that have values passed in code, or are bound to fields from the report's Fields collection using the DataField property. The total extended price for the OrderID is summarized using the following properties:

  • SummaryFunc: Sum (the default value)
    Adds values rather than counting or averaging them.
  • SummaryGroup: ghOrderID
    Summarizes the values that fall within the current OrderID group.
  • SummaryRunning: Group
    Calculates a running summary (each value is the sum of the current value and all preceding values) within the same group level.
  • SummaryType: SubTotal
    Summarizes the current group rather than a page or report total.

PageFooter section

The page footer section contains a static Label control that prints at the bottom of each page and contains the note on the number of pages in the report.
See Also

How To