ActiveReports 6 Online Help
Insert or Add Pages
See Also Send comments on this topic.
ActiveReports 6 > ActiveReports User Guide > How To > Insert or Add Pages

Glossary Item Box

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.

  1. Add the ActiveReports viewer control to the Windows Form. For more information, see the Adding ActiveReports Controls topic.
  2. Double-click the title bar of the Windows Form to create an event-handling method for the form's Load event.
  3. Add code to the handler to add rptTwo to rptOne

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

ShowTo 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

ShowTo write the code in C#

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.

  1. Add the ActiveReports viewer control to the Windows Form.
  2. Double-click the title bar of the Windows Form to create an event-handling method for the form's Load event.
  3. 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.

ShowTo 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

ShowTo write the code in C#

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.

  1. Add the ActiveReports viewer control to the Windows Form.
  2. Double-click the title bar of the Windows Form to create an event-handling method for the form's Load event.
  3. 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.

ShowTo 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))

ShowTo write the code in C#

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.

  1. Double-click the title bar of the Windows Form to create an event-handling method for the form's Load event.
  2. 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.

ShowTo 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

ShowTo write the code in C#

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;

See Also