Glossary Item Box

Samples | Walkthroughs | Parameters

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

Walkthrough: Parameters with Subreports

Parameters can be used with subreports to connect the subreport to the parent report. By setting a parameter for the field that links the parent report to the subreport, the parent report can pass the information to the subreport through the parameters.

Note   Subreports will not render PageHeader/Footer sections.

This walkthrough illustrates how to set up a subreport using parameters to link the parent report to the subreport.

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 two ActiveReports to a Visual Studio project

To add two 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 rptParent.
  4. Click Open.
  5. Click on Project > Add New Item.
  6. Select ActiveReports file and rename the file rptChild.
  7. Click Open.

Connecting the parent report to a data source

To connect the parent 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 suppliers order by country".
  7. Click OK to return to the report design surface.

Connecting the child report to a data source using parameters

To connect the child 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 products INNER JOIN categories ON products.categoryid = categories.categoryid WHERE products.supplierID =<%SupplierID%>".
  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 rptParent.
  2. Make the following changes to the group header:
    • Change the name to ghSuppliers
    • Change the DataField property to Country
  3. Add the following controls to rptParent, naming them as indicated:

     

    Control DataField Name Text/Caption Section Location
    TextBox Country txtCountry Country GroupHeader 0, 0
    TextBox CompanyName txtCompanyName Company Name Detail 0.0625, 0.0625
    TextBox ContactName txtContactName Contact Name Detail 2.312, 0.0625
    TextBox Phone txtPhone Phone Detail 4.562, 0.0625
    Subreport (Empty string) Subreport1 (Empty string) Detail 0.0625, 0.312

     

  4. Add a GroupHeader/Footer section to rptChild.
  5. Make the following changes to the group header:
    • Change the name to ghProducts
    • Change the DataField property to CategoryName
  6. Add the following controls to rptChild, naming them as indicated:

     

    Control DataField Name Text/Caption Section Location
    TextBox CategoryName txtCategoryName Category Name GroupHeader 0.0625, 0.0625
    TextBox ProductName txtProductName Product Name Detail 0.0625, 0.0625

Adding the code needed to link the subreport to the current record's supplierID

To write the code in Visual Basic

To write the code in C#

Adding the code to set the subreport's ShowParametersUI property to False

To write the code in Visual Basic

To write the code in C#

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 | Parameters

 

 


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