ActiveReports 18 .NET Edition
Developers / Working with Reports / Section Report / Insert or Add Report Pages
In This Topic
    Insert or Add Report Pages
    In This Topic

    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.

    Note: When you combine section reports into one document, you should always make sure that they have the same compatibility mode (CrossPlatform or GDI). Otherwise, you may get incorrect results.

    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 Windows Forms Viewer for more information.

    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.

    1. 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.
    2. 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
      
      rpt1.Document.Pages.Add(rpt2.Document.Pages(i))
      
      Next
      
      Viewer1.LoadDocument(rpt1.Document)
      

      To write the code in C#

      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.LoadDocument(rpt1.Document);
      

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

    1. 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.
    2. 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()
      rpt1.Run()
      Dim rpt2 As New rptTwo()
      rpt2.Run()
      rpt1.Document.Pages.AddRange(New GrapeCity.ActiveReports.Document.Section.Page() {rpt2.Document.Pages(1), rpt2.Document.Pages(2)})
      Viewer1.LoadDocument(rpt1.Document)

      To 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 GrapeCity.ActiveReports.Document.Section.Page[] {rpt2.Document.Pages[0],rpt2.Document.Pages[1]} );
      viewer1.LoadDocument(rpt1.Document);
      

    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.

    1. 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.
    2. 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()
      rpt1.Run()
      Dim rpt2 As New rptTwo()
      rpt2.Run()
      rpt1.Document.Pages.Insert(0, rpt2.Document.Pages(0))
      Viewer1.LoadDocument(rpt1.Document)

      To 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.Insert(0, rpt2.Document.Pages[0]);
      viewer1.LoadDocument(rpt1.Document);

    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.

    1. 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.
    2. 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()
      rpt1.Run()
      rpt1.Document.Pages.InsertNew(0)
      Viewer1.Document = rpt1.Document

      To write the code in C#

      C# code. Paste INSIDE the Form Load event.
      Copy Code
      rptOne rpt1 = new rptOne();
      rpt1.Run();
      rpt1.Document.Pages.InsertNew(0);
      viewer1.Document = rpt1.Document;