ActiveReports for .NET 3 Online Help Request technical support
Nested Subreports
See Also
User Guide > Samples and Walkthroughs > Walkthroughs > Standard Edition Walkthroughs > Advanced > Subreports Walkthroughs > Nested Subreports

Glossary Item Box

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.

Subreports will not render PageHeader/Footer sections, so you can delete them to save on processing time.

This walkthrough illustrates how to set up embedded subreports.

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 finished this walkthrough, you will have a report that looks similar to the following.

Adding three ActiveReports to a Visual Studio project

To add three ActiveReports to a Visual Studio 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 rptEmployees.
  4. Click Open.
  5. From the Project menu, select Add New Item.
  6. Select ActiveReports 3.0 File and rename the file rptOrders.
  7. Click Open.
  8. From the Project menu, select Add New Item.
  9. Select ActiveReports 3.0 File and rename the file rptCustomers.
  10. Click Open.

Connecting rptEmployees 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 * from employees".
  7. Click OK to return to the report design surface.

Connecting rptOrders 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 * from orders inner join [order details] on orders.orderID = [order details].orderID where orders.employeeID =
    <%employeeID%>".
  7. Click OK to return to the report design surface.

Connecting rptCustomers 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 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 * from customers where customerID = <%CustomerID%> ".
  7. Click OK to return to the report design surface.

Adding controls to display the data

To add controls to the reports

  1. Add a GroupHeader/Footer section to rptEmployees by right-clicking on the design surface of the report and selecting Insert > Report Header/Footer.
  2. Make the following changes to the group header:
    • Change the name to ghEmployees
    • Change the DataField property to EmployeeID
  3. Add the following controls to rptEmployees, setting the properties as indicated:

    Control Section DataField Name Text Location
    TextBox GroupHeader EmployeeID txtEmployeeID Employee ID 0, 0.3
    TextBox GroupHeader LastName txtLastName Last Name  3.375, 0.3
    TextBox GroupHeader FirstName txtFirstName First Name 1.125, 0.3
    TextBox GroupHeader Extension txtExtension Extension 2.25, 0.3
    Label GroupHeader lblEmployeeID Employee ID 0, 0
    Label GroupHeader lblLastName Last Name 1.125, 0
    Label GroupHeader lblFirstName First Name 1.125,  0
    Label GroupHeader lblExtension Extension 2.25, 0
    Subreport Detail   subOrders   0, 0

  4. Add the following controls to the Detail section of rptOrders, setting the properties as indicated.

    Control DataField Name Text Location
    TextBox OrderDate txtOrderDate Order Date 1.9375, 0.25
    TextBox Quantity txtQuantity Quantity 4.4375, 0.25
    TextBox orders.OrderID txtOrderID Order ID 0, 0.25
    TextBox ProductID txtProductID Product ID 3, 0.25
    Label lblOrderDate Order Date: 1.9375, 0
    Label lblQuantity Quantity: 4.4375, 0
    Label lblOrderID Order ID: 0, 0
    Label lblProductID Product ID: 3, 0
    Subreport subCustomers 0, 0.5
  5. Add the following controls to the Detail section of rptCustomers, setting the properties as indicated.
    Control DataField Name Text Location
    TextBox CompanyName txtCompanyName Company Name 0, 0.25
    TextBox ContactName txtContactName Contact Name 1.25, 0.25
    TextBox Phone txtPhone Phone 2.3125, 0.25
    Label Company Name lblCompanyName Company Name 0, 0
    Label Contact Name lblContactName Contact Name 1.25, 0
    Label Phone lblPhone Phone 2.3125, 0

Adding code to set the subOrders control in rptEmployees equal to rptOrders

To write the code in Visual Basic or C#

Adding code to set the subCustomers control in rptOrders equal to rptCustomers 

To write the code in Visual Basic or C#

Setting the ShowParametersUI property to false

To set the ShowParametersUI property to false

  1. Click in the dark gray area beneath rptCustomers to select the ActiveReport.
  2. In the properties window, change the ShowParametersUI property to False.
  3. In the same way, set the ShowParametersUI property to False for rptOrders

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 of rptEmployees. 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.