ActiveReports allows you to run multiple reports and combine their PagesCollections, or specified portions of them, into a single report. The document containing the merged reports can be saved to an RDF file or exported.
To add pages from one report to another
The Add method of the ActiveReports Document Pages Collection takes one parameter: value. The value parameter references a report document page. To add an entire report, use code like that in the example below to iterate through the entire pages collection of a report and append it to the first report.
- Add the ActiveReports viewer control to the Windows Form. For more information, see the Adding ActiveReports Controls topic.
- Double-click the title bar of the Windows Form to create an event-handling method for the form's Load event.
- Add code to the handler to add rptTwo 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 JUST ABOVE the Form Load event. | Copy Code |
|---|---|
| Dim i As Integer | |
| Visual Basic.NET code. Paste INSIDE the Form Load event. | Copy Code |
|---|---|
Dim rpt As New rptOne()
rpt.Run()
Viewer1.Document = rpt.Document
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
| |
| C# code. Paste JUST ABOVE the Form Load event. | Copy Code |
|---|---|
| int i; | |
| C# code. Paste INSIDE the Form Load event. | Copy Code |
|---|---|
rptOne rpt1 = new rptOne();
rpt1.Run();
Viewer1.Document = rpt.Document
rptTwo rpt2 = new rptTwo();
rpt2.Run();
for(i = 0; i < rpt2.Document.Pages.Count; i++)
{
rpt1.Document.Pages.Add(rpt2.Document.Pages[i]);
}
| |
To add a range of pages from one report to another
The AddRange method has two overloads, each with one parameter. The first overload takes an array of page objects, while the second takes a pages collection. Use the second overload to add an entire report's pages collection. Us the first (as in the example below) to append only specified pages from the second report onto the first.
- Add the ActiveReports viewer control to the Windows Form.
- Double-click the title bar of the Windows Form to create an event-handling method for the form's Load event.
- Add code to the handler to use the AddRange() method to add 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 rpt As New rptOne()
rpt.Run()
Dim rpt2 As New rptTwo()
rpt2.Run()
rpt1.Document.Pages.AddRange(New page()
{rpt2.Document.Pages(0), rpt2.Document.Pages(1)})
Viewer1.Document = rpt.Document
| |
| 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 page[]
{rpt2.Document.Pages[0],rpt2.Document.Pages[1]} );
viewer1.Document = rpt1.Document;
| |
To insert pages from one report into another
The Insert method takes two parameters, an index, which dictates where in the main report the pages are inserted, and value, the report page to insert.
- Add the ActiveReports viewer control to the Windows Form.
- Double-click the title bar of the Windows Form to create an event-handling method for the form's Load event.
- Add code to the handler to insert a second report at the beginning of the first
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 rpt As New rptInsertPage() Viewer1.Document = rpt.Document rpt.Run() Dim rpt2 As New rptCoverPage() rpt2.Run() rpt.Document.Pages.Insert(1, rpt2.Document.Pages(0)) | |
| C# code. Paste INSIDE the Form Load event. | Copy Code |
|---|---|
rptInsertPage rpt = new rptInsertPage(); viewer1.Document = rpt.Document; rpt.Run(); rptCoverPage rpt2 = new rptCoverPage(); rpt2.Run(); rpt.Document.Pages.Insert(1, rpt2.Document.Pages[0]); | |
To add code to insert a page into a specified report location
The InsertNew method takes one parameter, index, which specifies the page after which you want to insert a new blank page.
- Double-click the title bar of the Windows Form to create an event-handling method for the form's Load event.
- Add code to the handler to insert a page into a specific report location.
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 rpt As New rptInsertPage() rpt.Run() rpt.Document.Pages.InsertNew(3) Viewer1.Document = rpt.Document | |
| C# code. Paste INSIDE the Form Load event. | Copy Code |
|---|---|
rptInsertPage rpt = new rptInsertPage(); rpt.Run(); rpt.Document.Pages.InsertNew(3); viewer1.Document = rpt.Document; | |
Related Sections
Getting Started
Walkthroughs
Concepts
Hide All