Glossary Item Box

Samples | Walkthroughs | OutputFormat Strings

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

Walkthrough: Master Detail Reports with Subreports

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 (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. Click on Project > Add New Item.
  3. Select ActiveReports file and rename the file rptMaster.
  4. Click Open.
  5. Click on Project > Add New Item.
  6. Select ActiveReports 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 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 orders".
  7. 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 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 [order details] inner join products on [order details].productid = products.productID where [order details].orderID = <%OrderID%>".
  7. Click OK to return to the report design surface.

Adding controls to the report to contain data

To add controls to the report

  1. Add the following controls to the Detail section of rptMaster:

    Control DataField Name Text/Caption Misc Details Location
    Label (Empty string) lblOrderDate Order Date (Empty string) 0.0625, 0.0625
    Label (Empty string) lblShipName Ship Name (Empty string) 1.125, 0.0625
    Label (Empty string) lblShipDate Shipped Date (Empty string) 2.187, 0.0625
    Label (Empty string) lblShipAddress Ship Address (Empty string) 3.25, 0.0625
    Label (Empty string) lblShipCountry Ship Country (Empty string) 4.437, 0.0625
    Label (Empty string) lblFreight Freight (Empty string) 5.687, 0.0625
    Textbox OrderDate txtOrderDate Order Date (Empty string) 0.0625, 0.3125
    Textbox ShipName txtShipName Ship Name (Empty string) 1.125, 0.3125
    Textbox ShippedDate txtShippedDate Shipped Date (Empty string) 2.1875, 0.3125
    Textbox ShipAddress txtShipAddress Ship Address (Empty string) 3.25, 0.3125
    Textbox ShipCountry txtShipCountry Ship Country (Empty string) 4.4375, 0.3125
    Textbox Freight txtFreight Freight OutputFormat =

    Currency

    5.687, 0.3125
    Subreport (Empty string) ctlSubreport (Empty string) (Empty string) 0, 0.5625
    Label (Empty string) lblWhiteLine (Empty string) Background Color = White 0, 1.75
  2. Add the following controls to the Detail section of rptDetail:

    Control DataField Name Text/Caption Misc Details Location
    Textbox OrderID txtOrderID Order ID (Empty string) 0.0625, 0.25
    Textbox ProductName txtProductName Product Name (Empty string) 2.3125, 0.25
    Textbox products.ProductID txtProductID Product ID (Empty string) 1.1875, 0.25
    Textbox Quantity txtQuantity Quantity (Empty string) 3.4375, 0.25
    Textbox Discount txtDiscount Discount OutputFormat = Currency 4.5625, 0.25
    Label (Empty string) lblOrderID Order ID (Empty string) 0.0625, 0
    Label (Empty string) lblProductID Product ID (Empty string) 1.1875, 0
    Label (Empty string) lblProductName Product Name (Empty string) 2.3125, 0
    Label (Empty string) lblQuantity Quantity (Empty string) 3.4275, 0
    Label (Empty string) lblDiscount Discount (Empty string) 4.5625, 0

Adding code to retrieve subreport data during run time

To write the code in Visual Basic

To write the code in C#

The following example shows what the code for the method looks like.

' Visual Basic
Private Sub Detail_Format(ByVal sender As Object, ByVal e As System.EventArgs) Handles _ Detail.Format
Dim rpt As New rptDetail()
Me.ctlSubreport.Report = rpt
End Sub
//C#
private void Detail_Format (object sender, System.EventArgs e)
{
rptDetail rpt = new rptDetail();
this.ctlSubReport.Report = rpt;
}

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 | OutputFormat Strings

 

 


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