ActiveReports Developer 7
Calculated Fields Sample
See Also Support Forum
ActiveReports Developer 7 > ActiveReports Developer Guide > Samples and Walkthroughs > Samples > Section Report > Summary > Calculated Fields Sample

Glossary Item Box

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.


ShowSample Location

ShowVisual Basic.NET

<User Folder>\ComponentOne Samples\ActiveReports Developer 7\Section Reports\VB.NET\Summary\CalculatedFields

ShowC#

<User Folder>\ComponentOne Samples\ActiveReports Developer 7\Section Reports\C#\Summary\CustomAnnotation

ShowRuntime 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]\ComponentOne Samples\ActiveReports Developer 7\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.

ShowProject Details

ShowStartForm

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.

ShowOrdersReport

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.

ShowghOrderID 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.

ShowDetail section

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

ShowgfOrderID 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.

ShowPageFooter 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

©2014. ComponentOne, a division of GrapeCity. All rights reserved.