ActiveReports Developer 7
Embed Subreports
See Also Support Forum
ActiveReports Developer 7 > ActiveReports Developer Guide > How To > Section Report How To > Embed Subreports

Glossary Item Box

To embed a subreport into a parent report, you add two reports (one parent and one child report) to a Visual Studio project, and from the ActiveReports 7 Section Report toolbox, drag the SubReport control onto the parent report. The following steps take you through the process of adding a subreport in a section report.

These steps assume that you have already added a Section Report (code-based) template in a Visual Studio project. See Adding an ActiveReport to a Project for further information.

To add code to create an instance of the child report in the parent report

  1. Double-click the gray area around the parent report to create an event-handling method for the ReportStart event.
  2. Add code like the following to the handler to create a new instance of the child report.

    ShowTo write the code in Visual Basic

    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#

    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();
Caution: It is recommended that you 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, using a lot of memory.

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

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

    ShowTo write the code in Visual Basic

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

    ShowTo write the code in C#

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

See Also

©2014. ComponentOne, a division of GrapeCity. All rights reserved.