Glossary Item Box

Samples | Walkthroughs

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

Walkthrough: Simple Subreports

ActiveReports allows reports to contain any number of child reports by using the Subreport control. Child reports, or subreports, are executed each time the parent section (i.e. the section in which the Subreport control is placed) is printed.

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 a bound subreport by setting the Subreport control's Report property to the child report and how to modify the subreport record source from the data in the parent report to retrieve the correct information.

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 rptMain.
  4. Click Open.
  5. Click on Project > Add New Item.
  6. Select ActiveReports file and rename the file rptSub.
  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 categories".
  7. Click OK to return to the report design surface.

Adding controls to display the data

To add controls to the reports

  1. Add the following controls to the Detail section of rptMain, naming them as indicated:

    Control DataField Name Text/Caption Location
    Label (Empty string) lblProducts Products 1.0625, 0.25
    Label (Empty string) lblCategoryName Category Name: 0, 0
    TextBox CategoryName txtCategoryName CategoryName 1.06, 0
    Subreport (Empty string) ctlSubreport (Empty string) 1.0625, 0.5

  2. Add the following controls to the Detail section of rptSub, naming them as indicated:

    Control DataField Name Text/Caption Location
    TextBox ProductName txtProductName ProductName 1.187, 0.06
    Label (Empty string) lblProductName Product Name: 0.06, 0.06

Adding the code needed to save the current record's categoryID

Note: The Fields collection should never be accessed outside the DataInitialize and FetchData events.

To write the code in Visual Basic

To write the code in C#

Adding the code to create a new data source

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

 

 


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