ActiveReports for .NET 3 Online Help Request technical support
Walkthrough: Master Detail Reports with Subreports
See Also
User Guide > Samples and Walkthroughs > Walkthroughs > Standard Edition Walkthroughs > Basic > Master Detail Reports Walkthroughs > Walkthrough: Master Detail Reports with Subreports

Glossary Item Box

ActiveReports allows you to create Master Detail reports by using subreports to retrieve and group data.

This walkthrough illustrates how to create a Master Detail report with 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.

When you have completed 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 your 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 rptMaster.
  4. Click Open.
  5. From the Project menu, select Add New Item.
  6. Select ActiveReports 3.0 File and rename the file rptDetail.
  7. Click Open.

Connecting the Master report to a data source

To connect the Master report to a data source

  1. Click the gray report DataSource icon in the Detail section to open the report DataSource dialog.
  2. Select the "OLE DB" tab.
  3. Click the Build button.
  4. Select Microsoft Jet 4.0 OLE DB Provider and click Next.
  5. Click the ellipsis button to browse for the access path to the Northwind database. Click Open once you have selected the appropriate access path.
  6. Click OK to continue.
  7. In the Query field, type "Select * from orders".
  8. Click OK to return to the report design surface.

Connecting the Detail report to a data source

To connect the Detail report to a data source

  1. Click on the gray report DataSource icon in the Detail section to open the report DataSource dialog box.
  2. Select the "OLE DB" tab.
  3. Click the Build button.
  4. Select Microsoft Jet 4.0 OLE DB Provider and click Next.
  5. Click the ellipsis button to browse for the access path to the Northwind database. Click Open once you have selected the appropriate access path.
  6. Click OK to continue.
  7. In the Query field, type "Select * from [order details] inner join products on [order details].productid = products.productID where [order details].orderID = <%OrderID%>".
  8. Click OK to return to the report design surface.

Adding controls to rptMaster to contain data

To add controls to rptMaster

  1. Add a shape control to the detail section and make the following changes to it:
    • Set the BackColor property to Indigo
    • Set the LineColor property to Transparent
    • Set the Location property to 0, 0
    • Set the Size property to 6.5, 0.2
  2. Add labels with the following properties to the shape control:

    Font Style ForeColor Name Text Location
    Bold White lblOrderDate Order Date 0, 0
    Bold White lblShipName Ship Name 0.85, 0
    Bold White lblShipDate Ship Date 2.25, 0
    Bold White lblShipAddress Ship Address 2.98, 0
    Bold White lblShipCountry Ship Country 5, 0
    Bold White lblFreight Freight 5.97, 0
  3. Make the following changes to the detail section:
    • Set the BackColor property to MediumPurple
    • Set the CanShrink property to True
  4. Add the following controls to the detail section below the shape control:

    Control DataField Name Text Miscellaneous Location Size
    Textbox OrderDate txtOrderDate Order Date OutputFormat = MM/dd/yy 0, 0.25 0.75, 0.19
    Textbox ShipName txtShipName Ship Name 0.85, 0.25 1.34, 0.19
    Textbox ShippedDate txtShippedDate Shipped Date OutputFormat = MM/dd/yy 2.25, 0.25 0.65, 0.19
    Textbox ShipAddress txtShipAddress Ship Address 2.98, 0.25 2, 0.19
    Textbox ShipCountry txtShipCountry Ship Country 5, 0.25 0.9, 0.19
    Textbox Freight txtFreight Freight OutputFormat = Currency 5.97, 0.25 0.5, 0.19
    Subreport ctlSubReport 0.06, 0.53 6.38, 1
    Label lblWhiteLine BackColor = White 0, 1.66 6.5, 0.19

Adding controls to rptDetail to contain data

To add controls to rptDetail

  1. Delete the page header section. (Page headers are not displayed in subreports, so deleting them saves on processing time.)
  2. Set the ShowParameterUI property of the report to False to avoid asking users for parameters.
  3. Add a group header/footer to the report by right-clicking on the report and selecting Insert > Group Header/Footer.
  4. Set the BackColor property of the group header to LightBlue.
  5. Add labels with the following properties to the group header section:
    Font Style Name Text Location
    Bold lblOrderID Order ID 0, 0
    Bold lblProductID Product ID 0.81, 0
    Bold lblProductName Product Name 2.25, 0
    Bold lblQuantity Quantity 4.8, 0
    Bold lblDiscount Discount 5.5, 0
  6. Make the following changes to the detail section:
    • Set the BackColor property to LightBlue
    • Set the CanShrink property to True
  7. Add the following controls to the detail section:

    Control DataField Name Text Miscellaneous Location
    Textbox OrderID txtOrderID Order ID 0, 0
    Textbox products.ProductID txtProductID Product ID 0.81, 0
    Textbox ProductName txtProductName Product Name 2.25, 0
    Textbox Quantity txtQuantity Quantity 4.8, 0
    Textbox Discount txtDiscount Discount OutputFormat = Currency; Alignment = Right 5.5, 0

Adding code to retrieve subreport data during run time

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 rptMaster. 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.