By using the Subreport control, ActiveReports reports can contain any number of child reports. Child reports, or subreports, are executed each time the parent section (i.e. the section in which the Subreport control is placed) is printed.
![]() |
Subreports will not render PageHeader/Footer sections, so you can delete them to save processing time. |
This walkthrough illustrates how to set up a bound subreport by setting the Report property of the Subreport control to the child report. This walkthrough also demonstrates how to modify the subreport record source from the data in the parent report to retrieve the correct information.
This walkthrough is split up into the following activities:
- Adding two ActiveReports to a Visual Studio project
- Connecting each report to a data source
- Adding controls to each report to display the data
- Adding the code needed to set the subreport control equal to rptOrders
- 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 finished 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 a Visual Studio 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 rptCustomers.
- Click Open.
- From the Project menu, select Add New Item.
- Select ActiveReports 3.0 File and rename the file rptOrders.
- Click Open.
Connecting rptCustomers to a data source
To connect the report to a data source
- Click the gray report DataSource icon in the Detail section to open the report DataSource dialog.
- Click Build.
- Select Microsoft Jet 4.0 OLE DB Provider and click Next.
- Click the ellipsis 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 "SHAPE {SELECT CustomerID, CompanyName, Address FROM Customers} APPEND ({SELECT CustomerID, OrderID, Freight, OrderDate, EmployeeID FROM Orders} AS CustomerOrders RELATE CustomerID TO CustomerID)".
- Add "Provider=MSDataShape;" to the beginning of your Connection String and change "Provider=Microsoft.Jet.OLEDB.4.0;" to "Data Provider=Microsoft.Jet.OLEDB.4.0;". Your complete Connection String should look similar to: "Provider=MSDataShape;Data Provider=Microsoft.Jet.OLEDB.4.0;C:\Program Files\Data Dynamics\ActiveReports for .NET 3.0\Data\NWIND.MDB;Persist Security Info=False".
- Click OK to return to the report design surface.
Connecting rptOrders to a data source
To connect the report to a data source
- Click the gray report DataSource icon in the Detail section to open the report DataSource dialog.
- Click Build.
- Select Microsoft Jet 4.0 OLE DB Provider and click Next.
- Click the ellipsis 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 OrderDate, OrderID, Freight, EmployeeID FROM Orders".
- Click OK to return to the report design surface.
Adding controls to display the data
To add controls to the reports
- Add the following controls to the detail section of rptCustomers and set the properties as indicated.
Control DataField Name Text Location Miscellaneous TextBox CustomerID txtCustomerID Customer ID 0, 0 ForeColor=Blue; FontStyle=Bold TextBox CompanyName txtCompanyName Company Name 1.0625, 0 ForeColor=Blue; FontStyle=Bold TextBox Address txtAddress Address 3.9375, 0 ForeColor=Blue; FontStyle=Bold Subreport CustomerOrders Subreport1 0, 0.5 Size= 6.5, 1 - Add a GroupHeader/Footer section to rptOrders by right-clicking the design surface of the report and selecting Insert > Group Header/Footer.
- Make the following changes to the group header:
- Change the name to ghOrders
- Change the DataField property to CustomerID
- Add the following controls to rptOrders and set the properties as indicated.
Control Section Name DataField Text Location Miscellaneous Label GroupHeader lblOrderDate Order Date 0, 0 FontStyle=Bold; OutputFormat=MM/DD/YY Label GroupHeader lblOrderID Order ID 1.1875, 0 FontStyle=Bold Label GroupHeader lblFreight Freight 2.375, 0 FontStyle=Bold TextBox Detail txtOrderDate OrderDate Order Date 0, 0 0, 0 TextBox Detail txtOrderID OrderID Order ID 1.1875, 0 0, 0 TextBox Detail txtFreight Freight Freight 2.375, 0 0, 0 TextBox Detail txtEmployeeID Employee ID Employee ID 5.9375, 0 0, 0 Label Detail lblProcessed Processed by Employee ID #: 3.5625, 0 Font=Bold Line Detail line1 X1: 0 X2: 6.5
Y1: 0.25
Y2: 0.25
0, 0
Adding the code needed to set the subreport control equal to rptOrders
To write the code in Visual Basic or C#
- Double-click the gray area below rptCustomers. This creates an event-handling method for rptCustomers' ReportStart event. Add code to the handler to:
- Set the subreport control equal to rptOrders
The following example shows what the code for the method looks like.
'Visual Basic Private Sub rptCustomers_ReportStart(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles MyBase.ReportStart Me.SubReport1.Report = New rptOrders() End Sub //C# private void rptCustomers_ReportStart(object sender, System.EventArgs eArgs) { this.subReport1.Report = new rptOrders(); }
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 rptCustomers. 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. |