ActiveReports for .NET 3 Online Help Request technical support
Walkthrough: Summary Fields
See Also
User Guide > Samples and Walkthroughs > Walkthroughs > Standard Edition Walkthroughs > Basic > Walkthrough: Summary Fields

Glossary Item Box

In ActiveReports, summary fields can be added to any section to calculate totals, counts, averages and other aggregations. The summary field's placement dictates when the section containing the field, and sections after it, will be printed. A section with a summary field will be delayed until all the calculations are completed. This allows summary fields to be placed ahead of the corresponding detail.

Summary fields are calculated according to the textbox's Summary properties. A summary textbox is updated with each new detail record. When a field is placed ahead of the Detail section (i.e. in the ReportHeader, PageHeader or GroupHeader sections), the Detail section is formatted with each record and the summary field is updated. When all records for the summary level are read, the header section is printed followed by the delayed sections.

This walkthrough illustrates how to create a report with a summary field in the GroupFooter section.

This walkthrough is split up into the following activities:

To complete the walkthrough, you must have access to the Northwind database.
A copy is located at C:\Program Files\Data Dynamics\ActiveReports for .NET 3.0\Data\NWIND.MDB.

When you have completed this walkthrough, you will have a report that looks similar to the following.

Adding an ActiveReport to a Visual Studio project

To add an ActiveReport to your project

  1. Open a new project in Visual Studio.
  2. From the Project menu, select Add New Item.
  3. Select ActiveReports 3.0 File and rename the file rptSumFields.
  4. Click Open.

Connecting the report to a data source

To connect the report to a data source

  1. Click on the gray report DataSource icon in the Detail section to open the report DataSource dialog.
  2. Click on Build.
  3. Select Microsoft Jet 4.0 OLE DB Provider and click Next.
  4. Click the ellipsis button to browse for the access path to the NorthWind database. Click Open once you have selected the appropriate access path.
  5. Click OK to continue.
  6. In the Query field, type "SELECT DISTINCTROW Orders.*, [Order Details].*, Products.* FROM Products INNER JOIN (Orders INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID) ON Products.ProductID = [Order Details].ProductID order by orderdate".
  7. Click OK to return to the report design surface.

Adding controls to the report to contain data

To add controls to the report

  1. Add a GroupHeader/Footer section to rptSumFields by right-clicking the design surface of the report and selecting Insert > Group Header/Footer.
  2. Make the following changes to the group header:
    • Change the name to ghOrders
    • Change the DataField property to OrderDate
  3. Add the following controls to the GroupHeader section:

    Control Name Text Location
    Label lblOrderDate Order Date 0, 0
    Label lblProductID Product ID 1.208, 0
    Label lblProductName Product Name 2.489, 0
    Label lblUnitPrice Unit Price 4.56, 0

  4. In the Report Explorer, expand the Fields node, then the Bound node. Drag the following fields onto the detail section and set the following properties of each textbox as indicated. 

    Field Text Location Output Format
    Products.ProductID Product ID 1.218, 0
    ProductName Product Name 2.5, 0
    OrderDate Order Date 0, 0
    Products.UnitPrice Unit Price 4.562, 0 Currency
  5. Add the following controls to the GroupFooter section:

    Control DataField Name Text Location Miscellaneous
    Label lblSalesTotal Daily Sales Total: 3, 0
    TextBox products.UnitPrice txtSalesTotal Sales Total 4.562, 0 OutputFormat = Currency

    SummaryType = SubTotal

    SummaryRunning = Group

    SummaryGroup = ghOrders

    Label 0, 0.25

    Background color = white

    Size = 6.5, 0.083

 

Distinct summarization can be used in a situation when the field's value repeats in several detail records and the summary function needs to include a single value from all repeating values. To do this, you would need to set the DistinctField property of the summary field to the appropriate value and set the SummaryFunc property to the appropriate distinct summary function.

 

When used with Groups the SummaryRunning property should only be set when SummaryType is GrandTotal or PageTotal, otherwise it should be set to None.

 

 

Viewing the report

To view the report

  1. Add the ActiveReports viewer control to a Windows Form.
  2. Add the code needed to set the viewer document equal to the report document. See Using the ActiveReports Windows Form Viewer for help.
You can quickly view your report at design time by clicking the Preview tab at the bottom of the designer.

See Also

©2009. All Rights Reserved.