Glossary Item Box

Samples | Walkthroughs | Binding Reports to a Data Source | OutputFormat Strings | GroupKeepTogether enumeration

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

Walkthrough: Using Data Sets Containing Relationships with Subreports

In ActiveReports for .NET 2.0, data sets with relationships can be used to populate fields in subreports.

Note   Subreports will not render PageHeader/Footer sections.

This walkthrough illustrates how to use data sets 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 (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 rptCategories.
  4. Click Open.
  5. Click on Project > Add New Item.
  6. Select ActiveReports file and rename the file rptProductsSub.
  7. Click Open.
  8. Click on Project > Add New Item.
  9. Select ActiveReports 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.
  2. Make the following changes to the group header:
    • Change the name to ghCategories
    • Change the UnderlayNext property to True
    • Change the GroupKeepTogether property to FirstDetail
    • Change the DataField property to CategoryName
  3. Add the following controls to rptCategories, naming them as indicated:
    Control DataField Name Text/Caption Section Location
    Label (Empty string) lblCategoryName Category Name PageHeader 0, 0
    Label (Empty string) lblProduct Product PageHeader 1.25, 0
    Label (Empty string) lblOrderDetails Order Details PageHeader 2.75, 0
    TextBox CategoryName txtCategoryName Category Name GroupHeader 0, 0
    Subreport (Empty string) SubReport1 (Empty string) Detail 1.25, 0
  4. Add a GroupHeader/Footer section to rptProductsSub.
  5. Make the following changes to the group header:
    • Change the Name to ghProducts
    • Change the UnderlayNext property to True
    • Change the GroupKeepTogether property to FirstDetail
    • Change the DataField property to ProductName
  6. Add the following controls to rptProductsSub, naming them as indicated:

    Control DataField Name Text/Caption Section Location
    TextBox ProductName txtProductName Product Name GroupHeader 0, 0
    Label (Empty string) lblUnitPrice Unit Price Detail 1.4375, 0
    Label (Empty string) lblQuantity Quantity Detail 2.5625, 0
    Label (Empty string) lblPrice Price Detail 3.5625, 0
    Subreport (Empty string) SubReport1 (Empty string) Detail 1.4375, 0.1875
  7. Add the following controls to the Detail section of rptOrderDetailsSub, naming them as indicated:

    Control DataField Name Text/Caption OutputFormat Location
    TextBox UnitPrice txtUnitPrice Unit Price Currency 0, 0
    TextBox Quantity txtQuantity Quantity (Empty string) 1, 0
    TextBox Discount txtDiscount Discount Currency 2, 0

Setting the data connections, data adapters and data set relations

To set the data connections

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

To write the code for the viewer in Visual Basic

To write the code for the viewer 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 | Binding Reports to a Data Source | OutputFormat Strings | GroupKeepTogether enumeration

 

 


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