In a section layout, you can run multiple reports, merge their entire page collection or specific portions and view it as a single report. You can save the document containing merged reports to an RDF file or even export them.
These steps assume that you have already placed a Viewer control on a Windows Form and your Visual Studio project contains two section layout (code based) reports (rptOne and rptTwo). See Adding an ActiveReport to a Project and Using the Viewer for more information.
To add pages from one report to another
To add an entire report to another, use code like the one in the example below to iterate through the entire pages collection of a report and append it to the first report. The Add of the PagesCollection takes one parameter (value), which references a report document page.
- In the design view of the Form containing the Viewer, double-click the title bar of the Form to create an event-handling method for the Form_Load event.
- Add the following code to the handler to add the entire rptTwo page collection to rptOne.
The following example shows what the code for the Add() method looks like.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the Form Load event. | Copy Code |
---|---|
Dim i As Integer Dim rpt As New rptOne() rpt.Run() Dim rpt2 As New rptTwo() rpt2.Run() For i = 0 To rpt2.Document.Pages.Count - 1 rpt.Document.Pages.Add(rpt2.Document.Pages(i)) Next Viewer1.Document = rpt.Document |
C# code. Paste INSIDE the Form Load event. | Copy Code |
---|---|
int i; rptOne rpt1 = new rptOne(); rpt1.Run(); rptTwo rpt2 = new rptTwo(); rpt2.Run(); for(i = 0; i < rpt2.Document.Pages.Count; i++) { rpt1.Document.Pages.Add(rpt2.Document.Pages[i]); } viewer1.Document = rpt1.Document; |
To add a range of pages from one report to another
To add a range of pages from one report to another, use the AddRange. This method has two overloads, each with one parameter. The first overload takes an array of page objects which you can use to append only the specified pages from the second report onto the first (as in the example below).
- In the design view of the Form containing the Viewer, double-click the title bar of the Form to create an event-handling method for the Form_Load event.
- Add the following code to the handler to use the AddRange() method to add pages from rptTwo to rptOne.
The following example shows what the code for the AddRange() method looks like.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the Form Load event. | Copy Code |
---|---|
Dim rpt1 As New rptOne() |
C# code. Paste INSIDE the Form Load event. | Copy Code |
---|---|
rptOne rpt1 = new rptOne(); rpt1.Run(); rptTwo rpt2 = new rptTwo(); rpt2.Run(); rpt1.Document.Pages.AddRange(new GrapeCity.ActiveReports.Document.Section.Page[] {rpt2.Document.Pages[0],rpt2.Document.Pages[1]} ); viewer1.Document = rpt1.Document; |
To insert pages from one report into another
To insert pages from one report to another, use the Insert that takes two parameters, an index, which determines where to insert the pages in the main report, and a value which references the report page to insert.
- In the design view of the Form containing the Viewer, double-click the title bar of the Form to create an event-handling method for the Form_Load event.
- Add the following code to the handler to insert page 1 of rptTwo at the beginning of rptOne.
The following example shows what the code for the Insert() method looks like.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the Form Load event. | Copy Code |
---|---|
Dim rpt1 As New rptOne() |
C# code. Paste INSIDE the Form Load event. | Copy Code |
---|---|
rptOne rpt1 = new rptOne(); |
To insert a new page at a specific report location
To insert a new blank page at a specific location in the report, use the InsertNew which takes one parameter, index, which specifies the page after which you want to insert a new blank page.
- In the design view of the viewer form, double-click the title bar of the Form to create an event-handling method for the Form_Load event.
- Add the following code to the handler to insert a blank page at the beginning of rptOne.
The following example shows what the code for the InsertNew() method looks like.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the Form Load event. | Copy Code |
---|---|
Dim rpt1 As New rptOne() |
C# code. Paste INSIDE the Form Load event. | Copy Code |
---|---|
rptOne rpt1 = new rptOne(); |