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:
- Adding two ActiveReports to a Visual Studio project
- Connecting the Master report to a data source
- Connecting the Detail report to a data source
- Adding controls to rptMaster to contain data
- Adding controls to rptDetail to contain data
- Adding code to retrieve the subreport data at run time
- Viewing the report
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
- Open a new project in Visual Studio.
- From the Project menu, select Add New Item.
- Select ActiveReports 3.0 File and rename the file rptMaster.
- Click Open.
- From the Project menu, select Add New Item.
- Select ActiveReports 3.0 File and rename the file rptDetail.
- Click Open.
Connecting the Master report to a data source
To connect the Master report to a data source
- Click the gray report DataSource icon in the Detail section to open the report DataSource dialog.
- Select the "OLE DB" tab.
- Click the Build button.
- Select Microsoft Jet 4.0 OLE DB Provider and click Next.
- Click the ellipsis button to browse for the access path to the Northwind database. Click Open once you have selected the appropriate access path.
- Click OK to continue.
- In the Query field, type "Select * from orders".
- 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
- Click on the gray report DataSource icon in the Detail section to open the report DataSource dialog box.
- Select the "OLE DB" tab.
- Click the Build button.
- Select Microsoft Jet 4.0 OLE DB Provider and click Next.
- Click the ellipsis button to browse for the access path to the Northwind database. Click Open once you have selected the appropriate access path.
- Click OK to continue.
- In the Query field, type "Select * from [order details] inner join products on [order details].productid = products.productID where [order details].orderID = <%OrderID%>".
- Click OK to return to the report design surface.
Adding controls to rptMaster to contain data
To add controls to rptMaster
- 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
- 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 - Make the following changes to the detail section:
- Set the BackColor property to MediumPurple
- Set the CanShrink property to True
- 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
- Delete the page header section. (Page headers are not displayed in subreports, so deleting them saves on processing time.)
- Set the ShowParameterUI property of the report to False to avoid asking users for parameters.
- Add a group header/footer to the report by right-clicking on the report and selecting Insert > Group Header/Footer.
- Set the BackColor property of the group header to LightBlue.
- 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 - Make the following changes to the detail section:
- Set the BackColor property to LightBlue
- Set the CanShrink property to True
- 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#
- Double-click the Detail section of rptMaster to create an event-handling method for rptMaster's Detail_Format event. Add code to the handler to:
- Retrieve subreport data at run time
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
- Add the ActiveReports viewer control to a Windows Form.
- 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. |
