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.
<User Folder>\ComponentOne Samples\ActiveReports Developer 7\Section Reports\VB.NET\Summary\CalculatedFields
<User Folder>\ComponentOne Samples\ActiveReports Developer 7\Section Reports\C#\Summary\CustomAnnotation
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. |
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.
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. |
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.
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.
How To
Add Field Expressions