ActiveReports 6 Online Help
Embed Subreports in a Report
See Also Send comments on this topic.
ActiveReports 6 > ActiveReports User Guide > How To > Embed Subreports in a Report

Glossary Item Box

To embed a subreport into a parent report, you add two reports to a Visual Studio project, and from the ActiveReports toolbox, drag the SubReport control onto one of the reports. You can then add code to create an instance of the child report, and to display it in the SubReport control.

To add code to create an instance of the child report

Warning: Do not create a new instance of the subreport in the Format event. Doing so creates a new subreport each time the section Format code is run, which uses a lot of memory.

ShowTo write the code in Visual Basic

  1. At the top left of the code view for the parent report, click the drop-down arrow and select (rptYourParentReportName Events).
  2. At the top right of the code window, click the drop-down arrow and select ReportStart. This creates an event-handling method for the report's ReportStart event.
  3. Add code to the handler to create a new instance of the child report.

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

Visual Basic.NET code. Paste JUST ABOVE the ReportStart event. Copy Code
Dim rpt As rptYourChildReportName
Visual Basic.NET code. Paste INSIDE the ReportStart event. Copy Code
rpt = New rptYourChildReportName()

ShowTo write the code in C#

  1. Click in the gray area below the parent report to select it.
  2. Click the events icon in the Properties Window to display available events for the report.
  3. Double-click ReportStart. This creates an event-handling method for the report's ReportStart event.
  4. Add code to the handler to create a new instance of the child report.

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

C# code. Paste JUST ABOVE the ReportStart event. Copy Code
private rptYourChildReportName rpt;
C# code. Paste INSIDE the ReportStart event. Copy Code
rpt = new rptYourChildReportName();

To add code to display the child report in a subreport control on a parent report

  1. Double-click in the detail section of the design surface of the parent report to create a detail_Format event.
  2. Add code to the handler to display a report in the subreport control.

ShowTo write the code in Visual Basic

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

Visual Basic.NET code. Paste INSIDE the Format event. Copy Code
Me.SubReport1.Report = rpt

ShowTo write the code in C#

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

C# code. Paste INSIDE the Format event. Copy Code
this.subReport1.Report = rpt;

See Also