Glossary Item Box

Samples | Walkthroughs

See Also ActiveReports for .NET 2 Online Help Send feedback to Data Dynamics

Nested Subreports

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.

Note: 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 (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. Click on Project > Add New Item.
  3. Select ActiveReports file and rename the file rptEmployees.
  4. Click Open.
  5. Click on Project > Add New Item.
  6. Select ActiveReports file and rename the file rptOrders.
  7. Click Open.
  8. Click on Project > Add New Item.
  9. Select ActiveReports 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 yellow report DataSource icon in the Detail section. This brings up the report DataSource dialog box.
  2. Click on Build...
  3. Select Microsoft Jet 4.0 OLE DB Provider and click Next >>
  4. Click on the ellipsis to browse for the access path to NWind.mdb. 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 yellow report DataSource icon in the Detail section. This brings up the report DataSource dialog box.
  2. Click on Build...
  3. Select Microsoft Jet 4.0 OLE DB Provider and click Next >>
  4. Click on the ellipsis to browse for the access path to NWind.mdb. 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 yellow report DataSource icon in the Detail section. This brings up the report DataSource dialog box.
  2. Click on Build...
  3. Select Microsoft Jet 4.0 OLE DB Provider and click Next >>
  4. Click on the ellipsis to browse for the access path to NWind.mdb. 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
  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, naming them as indicated:

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

  4. Add the following controls to the Detail section of rptOrders, naming them as indicated:

    Control DataField Name Text/Caption 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 (Empty string) lblOrderDate Order Date: 1.9375, 0
    Label (Empty string) lblQuantity Quantity: 4.4375, 0
    Label (Empty string) lblOrderID Order ID: 0, 0
    Label (Empty string) lblProductID Product ID: 3, 0
    Subreport (Empty string) subCustomers (Empty string) 0, 0.5
  5. Add the following controls to the Detail section of rptCustomers, naming them as indicated:

    Control DataField Name Text/Caption 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 (Empty string) lblCompanyName Company Name 0, 0
    Label (Empty string) lblContactName Contact Name 1.25, 0
    Label (Empty string) lblPhone Phone 2.3125, 0

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

To write the code in Visual Basic

To write the code in C#

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

To write the code in Visual Basic

To write the code in C#

Setting the ShowParametersUI property to false

To set the ShowParametersUI property to false

  1. Click in the dark gray area underneath 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. See Using the ActiveReports WinForm Viewer for help.

Samples | Walkthroughs

 

 


Copyright © 2004-2005 Data Dynamics, Ltd. All rights reserved.