ActiveReports 6 Online Help
Nested Subreports
Show AllShow All
Hide AllHide All

When setting up embedded subreports in ActiveReports, the principles are the same as when setting up simple subreports but are applied to the child-grandchild reports. This walkthrough illustrates how to set up embedded subreports.

This walkthrough is split up into the following activities:

Tip: For basic steps like viewing a report, please see the Basic Data Bound Reports walkthrough.

To complete the walkthrough, you must have access to the Northwind database.
A copy is located at C:\Program Files\GrapeCity\ActiveReports 6\Data\NWIND.MDB (on a 64-bit Windows operating system, a copy is located in C:\Program Files (x86)\GrapeCity\ActiveReports 6\Data\NWIND.MDB).

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

To create parent, child, and grandchild reports

  1. Open a new project in Visual Studio.
  2. From the Project menu, select Add New Item.
  3. Select ActiveReports 6 (code-based) File and rename the file rptEmployees.
  4. Click Open.
  5. Repeat for rptCustomers and rptOrders.

To connect the parent report, rptEmployees, to a data source

  1. Click the gray report DataSource icon on the Detail section band to open the Report Data Source dialog.
  2. On the "OLE DB" tab, next to Connection String, click the Build button.
  3. In the Data Link Properties window that appears, select Microsoft Jet 4.0 OLE DB Provider and click the Next button.
  4. Click the ellipsis (...) button to browse to the Northwind database. Click Open once you have selected the appropriate access path.
  5. Click OK to close the window and fill in the Connection String field.
  6. In the Query field, enter the following SQL query
    SQL Query
    Copy Code
    SELECT Employees.EmployeeID, Employees.LastName, Employees.FirstName, Employees.Extension, Customers.CustomerID
    FROM Customers, Employees
    ORDER BY Employees.EmployeeID, Customers.CustomerID
  7. Click OK to save the data source and return to the report design surface.
    Note: This query joins the Employees table for the parent report to the Customers table for the subreport.

To connect the child report, rptCustomers, to a data source

  1. Click the gray report DataSource icon on the Detail section band to open the Report Data Source dialog.
  2. On the "OLE DB" tab, next to Connection String, click the Build button.
  3. In the Data Link Properties window that appears, select Microsoft Jet 4.0 OLE DB Provider and click the Next button.
  4. Click the ellipsis (...) button to browse to the Northwind database. Click Open once you have selected the appropriate access path.
  5. Click OK to close the window and fill in the Connection String field.
  6. In the Query field, enter the following SQL query
    SQL Query
    Copy Code
    SELECT Customers.*, Employees.EmployeeID, Orders.OrderID
    FROM Employees INNER JOIN (Customers INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID) ON Employees.EmployeeID = Orders.EmployeeID
    WHERE Customers.CustomerID = '<%CustomerID%>'
  7. Click OK to save the data source and return to the report design surface.

Note: This SQL query uses parameters syntax: '<%CustomerID%>'. For more information on parameters, see the Parameters topic.

To connect the grandchild report, rptOrders, to a data source

  1. Click the gray report DataSource icon on the Detail section band to open the Report Data Source dialog.
  2. On the "OLE DB" tab, next to Connection String, click the Build button.
  3. In the Data Link Properties window that appears, select Microsoft Jet 4.0 OLE DB Provider and click the Next button.
  4. Click the ellipsis (...) button to browse to the Northwind database. Click Open once you have selected the appropriate access path.
  5. Click OK to close the window and fill in the Connection String field.
  6. In the Query field, enter the following SQL query
    SQL Query
    Copy Code
    SELECT * FROM Orders WHERE EmployeeID = <%EmployeeID%>
  7. Click OK to save the data source and return to the report design surface.

To add controls to the parent report, rptEmployees, to display data

  1. Right-click on the design surface of rptEmployees and select Insert, then Group Header/Footer to add a group header and a group footer section to the report.
  2. With the group header selected in the Properties Window, make the following changes:
    • Name: ghEmployees
    • DataField: EmployeeID
    • Height: 0.6
  3. Set the Height property of the page header section to 0.3.
  4. Set the CanShrink property of the Detail section to True to eliminate white space.
  5. In the Report Explorer, expand the Fields node, then the Bound node. Drag the following fields onto the group header section and set the properties of each textbox as indicated.

    Group header fields

  6. Drag the following controls from the ActiveReports Toolbox onto the indicated section of rptEmployees, setting the properties as indicated.

    Other controls

To add controls to the child report, rptCustomers, to display data

Since the subreport control in the parent report that displays this report is 5.4 inches wide, none of the controls on this report extend beyond 5.4 inches. If you need a visual reminder, you can resize the child report by dragging the right edge inward or by changing the PrintWidth property.

  1. Click in the gray area below rptCustomers to select the report.
  2. In the Properties Window, change the ShowParametersUI property to False. This prevents the subreport from requesting parameter values from the user.
  3. Select the Detail section and set the CanShrink property to True to eliminate white space.
  4. Set the BackColor property of the Detail section to AliceBlue to distinguish the subreport from the main report.
    Tip: Even if you do not want colors in your finished reports, using background colors on subreports can help in troubleshooting layout issues.
  5. Right-click the PageHeader or PageFooter section and select Delete. Subreports do not render these sections, so deleting them saves processing time.
  6. Drag the following controls from the ActiveReports toolbox onto the Detail section of rptCustomers, setting the properties as indicated.

    Detail section controls

To add controls to the grandchild report, rptOrders, to display data

Since the subreport control in the child report that displays this report is 3 inches wide, none of the controls on this report extend beyond 3 inches. If you need a visual reminder, you can resize the child report by dragging the right edge inward or by changing the PrintWidth property.

  1. Click in the gray area below rptOrders to select the report.
  2. In the Properties Window, change the ShowParametersUI property to False.
  3. Select the Detail section and set the CanShrink property to True to eliminate white space.
  4. Set the BackColor property of the Detail section to Lavender to distinguish the subreport from the main report.
  5. Right-click the PageHeader or PageFooter section and select Delete.
  6. Add the following controls to the Detail section of rptOrders, setting the properties as indicated.

    Detail section controls

To add code to display rptCustomers in the subreport control on rptEmployees

Warning: Do not create a new instance of the subreport in the Format event. Doing so creates a new subreport each time the section Format code is run, which uses a lot of memory.

To write the code in Visual Basic

To write the code in C#

To add code to display rptOrders in the subreport control on rptCustomers

To write the code in Visual Basic

To write the code in C#