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.
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
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:
PageFooter section