ActiveReports for .NET 3 Online Help Request technical support
Walkthrough: Using DataSets Containing Relationships with Subreports
See Also
User Guide > Samples and Walkthroughs > Walkthroughs > Standard Edition Walkthroughs > Advanced > Walkthrough: Using DataSets Containing Relationships with Subreports

Glossary Item Box

In ActiveReports for .NET 3.0, datasets with relationships can be used to populate fields in subreports.

Subreports do not render PageHeader/Footer sections. To save on processing time, always delete PageHeader/Footer sections from subreports.

This walkthrough illustrates how to use datasets with relationships in nested 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.

We will be establishing a relationship between the Categories, Products, and Order Details tables at run time.

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 rptCategories.
  4. Click Open.
  5. From the Project menu, select Add New Item.
  6. Select ActiveReports 3.0 File and rename the file rptProductsSub.
  7. Click Open.
  8. From the Project menu, select Add New Item.
  9. Select ActiveReports 3.0 File and rename the file rptOrderDetailsSub.
  10. Click Open.

Adding controls to display the data

To add controls to the reports

  1. Add a GroupHeader/Footer section to rptCategories 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 property to ghCategories
    • Change the UnderlayNext property to True
    • Change the GroupKeepTogether property to All
    • Change the DataField property to CategoryName
    • Change the BackColor property to Gainsboro
  3. Change the BackColor property of the page header to Silver.
  4. Add the following controls to rptCategories, setting the properties as indicated:
    Control DataField Name Text Section Location Font Size
    Label lblCategoryName Category Name PageHeader 0, 0 12
    Label lblProduct Product PageHeader 1.5, 0 12
    Label lblOrderDetails Order Details PageHeader 2.75, 0 12
    TextBox CategoryName txtCategoryName Category Name GroupHeader 0, 0
    Subreport SubReport1 Detail 1.5, 0
  5. Add a GroupHeader/Footer section to rptProductsSub by right-clicking the design surface of the report and selecting Insert > Group Header/Footer.
  6. Make the following changes to the group header:
    • Change the Name property to ghProducts
    • Change the UnderlayNext property to True
    • Change the GroupKeepTogether property to All
    • Set the DataField property to ProductName
    • Change the BackColor property to LightSteelBlue
  7. Add the following controls to rptProductsSub, setting the properties as indicated:

    Control Miscellaneous Name Text Section Location
    TextBox DataField = ProductName txtProductName Product Name GroupHeader 0, 0
    Label Underlined lblUnitPrice Unit Price Detail 1, 0
    Label Underlined lblQuantity Quantity Detail 1.75, 0
    Label Underlined lblDiscount Discount Detail 2.44, 0
    Subreport SubReport1 Detail 1, 0.25
  8. Add the following controls to rptOrderDetailsSub, setting the properties as indicated:

    Control DataField Name Text OutputFormat Alignment Location
    TextBox UnitPrice txtUnitPrice Unit Price Currency Right 0, 0
    TextBox Quantity txtQuantity Quantity Right 0.75, 0
    TextBox Discount txtDiscount Discount 0% Right 1.44, 0
  9. Set the CanShrink property of the detail section to True.

Setting the data connections, data adapters and dataset relations

To set the data connections

  1. Add a Windows Form to your project.
  2. Add an ActiveReports viewer control to the Windows Form and set the Dock property to Fill.

To write the code for the viewer in Visual Basic or C#

Adding code to set the subreport's data source control equal to the dataset's returned row collection for rptCategories

To write the code in Visual Basic or C#

Adding code to set the subreport's data source control equal to the dataset's returned row collection for rptProductsSub

To write the code in Visual Basic or 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 of rptCategories. 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.