ActiveReports 6 Online Help
SubReports Sample

The SubReports sample consists of a StartForm with an ActiveReports Viewer control with two buttons, one to run and load each main report, and four reports.

StartForm

The StartForm has a Viewer control with its Dock property set to Fill. This ensures that the viewer resizes along with the form at run time. It also has a panel docked to the top that holds two buttons to run the two main reports. Right-click the form and select View Code to see the code that accomplishes this.

Code

The Click event of the Run SubReport button runs a new Customers report and loads it into the viewer. The Click event of the Orders Report button runs a new Orders report and loads it into the viewer.

Customers Report

The Customers report uses only the Detail section. It uses several Label controls and bound TextBox controls to display customer data, and a SubReport control to display details about the current customer's orders. This section renders once for each line of data found. The data source icon is not used in this report, as the data, along with the subreport, is set up in code. Right-click the report and select View Code to see the code that accomplishes this.

Code

In the ReportStart event, a new instance of the Orders report is created. This event is the most efficient place to instantiate reports for use in subreport controls as it fires only once when the report is run.

The DataInitialize event is where the data source and SQL query for the main report is set. The data source for the subreport is set in the Detail Format event.

For more information on subreport usage, see Subreports.

Orders Report

The Orders report is displayed in the SubReport control in the Customers report. The PageHeader and PageFooter sections have been removed because these sections do not display in the SubReport control. This avoids the use of processing time and resources for sections that do not render.

This report uses the GroupHeader section to display static labels for the data in the Detail section. The Detail section displays all of the order data for the current customer in the main report.

OrdersMasterReport

The OrdersMasterReport displays general information about orders, and uses a subreport to display the order details.

ReportHeader Section

This section uses static Label controls to display labels for the details to follow.

PageHeader Section

Since this section is not in use, its Height property is set to 0. The section cannot be deleted because the related PageFooter section is in use.

Detail Section

Click the gray report DataSource icon on the Detail section band to open the Report Data Source dialog, where you can see the Connection String and SQL Query that provide data for the bound fields.

The Detail section has six bound TextBox controls that display a list of order information, and one SubReport control that displays the OrdersDetailReport.

PageFooter Section

This section, which renders once per page, uses the ReportInfo control to display page n of m at the bottom of each page.

ReportFooter Section

This section is not used, but cannot be deleted because the related ReportHeader section is in use.

Code

The report for the SubReport control, OrdersDetailReport, is instantiated and assigned to the SubReport control in the ReportStart event.

OrdersDetailReport

This report has static Label controls in the ReportHeader section, and bound TextBoxes in the Detail section.

Click the gray report DataSource icon on the Detail section band to open the Report Data Source dialog, where you can see the Connection String and SQL Query that provide data for the bound fields.