ActiveReports 6 Online Help
Annual Report Sample

The Annual Report sample demonstrates the use of subreports, section properties, and the Chart control. See a description of each file below.

AnnualReport

This is the main ActiveReport for the project.

ReportHeader Section

This report features a two-page ReportHeader section that uses a PageBreak control to separate the two pages, and breaks to the second page by setting the ReportHeader section's NewPage property to After. This report shows how you can use the BackColor and ForeColor properties of labels to create a distinctive look for your reports.

The ReportHeader section also has a SubReport control that links to the ProductSalesByCategory report in the code behind the report, in the ReportStart event.

Best practice: It is a best practice to initialize reports in the ReportStart event rather than a section Format event so that a new report is not initialized every time the section runs.

If the SubReport control were in a section that prints multiple times, you would need to assign the report in the section Format event while still initializing in the ReportStart event. See the SubReports sample for more information.

The yellow background in the right half of the ReportHeader below the page break is achieved by using the Shape control and setting its BackColor property. The image to the left is a Picture control.

Detail Section

The Detail section contains two SubReport controls that link in the code behind the report to the Top10Customers and Top10Products reports. In most reports, the Detail section would run multiple times. In this report, the Detail section has only labels, and no bound textboxes, so it will only run once. Therefore, the Top10 reports can be assigned to the SubReport control in the ReportStart event where it is initialized.

Notice that the ReportFooter section has its Height property set to 0. This is because, except for the Detail section, all sections come in pairs. In order to use the ReportHeader section, you must also have a ReportFooter section. If you do not want to use it, you can set its Height to 0.

GetDBPath

This is a helper class that finds the installation path of ActiveReports, and extrapolates the path of the sample NorthWind database that is included in the installation. It returns a connection string that is used by all of the ActiveReports samples that use the NorthWind database.

ProductSalesByCategory

This is the ActiveReport that is assigned to the SubReport control in the ReportHeader section of the Annual Report.

Best practice: Notice that this report has had its ReportHeader/Footer and PageHeader/Footer sections removed. That is a best practice for reports to be used as subreports. These sections are not printed within the SubReport control, so removing the sections saves on processing.

Notice also that the PrintWidth property of this report is only 2.677 inches. This is so that it fits easily within the SubReport control on the Annual Report.

This report uses the GroupHeader section to display labels for the data fields that fill the Detail section. The fields in the Detail section repeat once for each row of data in the database.

Right-click in the grey area around the report and select View Code to see the code that sets the data source for the report, and sets the background color to yellow on every second row of data.

StartupForm

This form contains the ActiveReports Viewer control. The Dock property of the viewer is set to Fill so that it resizes automatically with the form at run time. Right-click and select View Code to see the code that displays the AnnualReport when the form loads.

Top10Customers and Top10Products

The Top10Customers and Top10Products reports use only two sections, GroupHeader and Detail. The PrintWidth property of each report is set to 3.135 inches so that it fits into the subreport control on the Annual Report.

The GroupHeader section of each report is filled with a Chart control. Click the chart to see its properties in the Properties window. At the bottom of the Properties window, click the Data Source verb to open the Chart Data Source dialog. In the Query box, you can see the SQL query that selects the top 10. For more information on creating charts, see Chart Walkthroughs.

The Detail section of each report has two bound TextBoxes and a Label control. Right-click and select View Code to see the code that sets the data source for the report, passes data to the Chart control, alternates the background color of the detail section, and sets the Text property of the label.