ActiveReports for .NET 3 Online Help Request technical support
Walkthrough: Merging Reports
See Also
User Guide > Samples and Walkthroughs > Walkthroughs > Standard Edition Walkthroughs > Advanced > Modifying Report Documents Walkthroughs > Walkthrough: Merging Reports

Glossary Item Box

ActiveReports allows you to merge two or more reports in Visual Studio for previewing in the viewer control or printing. The document containing the merged reports can also be saved to an RDF file or exported.

This walkthrough illustrates how to create two ActiveReports and merge the reports into one document.

This walkthrough is split up into the following activities:

To complete the walkthrough, you must have access to the Northwind database.
A copy is located at C:\Program Files\Data Dynamics\ActiveReports for .NET 3.0\Data\NWIND.MDB.

When you have completed this walkthrough, you will have a report that looks similar to the following.

Adding two ActiveReports to a Visual Studio project

To add two ActiveReports to a Visual Studio project

  1. Open a new project in Visual Studio.
  2. From the Project menu, select Add New Item.
  3. Select ActiveReports 3.0 File and rename the file rptOne.
  4. Click Open.
  5. From the Project menu, select Add New Item.
  6. Select ActiveReports 3.0 File and rename the file rptTwo.
  7. Click Open.

Connecting the reports to a data source

To connect rptOne to a data source

  1. Click on the gray report DataSource icon in the Detail section to open the report DataSource dialog.
  2. Select the "OLE DB" tab.
  3. Click the Build button.
  4. Select Microsoft Jet 4.0 OLE DB Provider and click Next.
  5. Click the ellipsis button to browse for the access path to the Northwind database. Click Open once you have selected the appropriate access path.
  6. Click OK to continue.
  7. In the Query field, type "Select * from orders".
  8. Click OK to return to the report design surface.

To connect rptTwo to a data source

  1. Click on the gray report DataSource icon in the Detail section to open the report DataSource dialog.
  2. Select the "OLE DB" tab.
  3. Click on Build.
  4. Select Microsoft Jet 4.0 OLE DB Provider and click Next.
  5. Click the ellipsis button to browse for the access path to the Northwind database. Click Open once you have selected the appropriate access path.
  6. Click OK to continue.
  7. In the Query field, type "Select * from products".
  8. Click OK to return to the report design surface.

Adding controls to display the data

To add controls to rptOne

  1. Change the following properties of the detail section:
    • Set the BackColor property to Thistle
    • Set the CanShrink property to True
  2. In the Report Explorer, expand the Fields node, then the Bound node. Drag the following fields onto the detail section and set the properties of each textbox as indicated.

    DataField Text Location Size OutputFormat
    OrderDate Order Date 0, 0 0.6, 0.19  MM/dd/yy
    OrderID Order ID 0.69, 0 0.5, 0.19
    ShipName Ship Name 1.25, 0 1.94, 0.19
    ShipAddress Ship Address 3.25, 0 2.3, 0.19
    ShipCity Ship City 5.63, 0 0.88, 0.19

To add controls to rptTwo

  1. Change the following properties of the detail section:
    • Set the BackColor property to LightSteelBlue
    • Set the CanShrink property to True
  2. Drag the following fields onto the detail section and set the properties of each textbox as indicated.

    DataField Text Location Size
    ProductID Product ID 0, 0 0.88, 0.19
    ProductName Product Name 1, 0 2.44, 0.19
    QuantityPerUnit Quantity Per Unit 3.5, 0 1.38, 0.19
    ReorderLevel Reorder Level 4.94, 0 0.75, 0.19
    UnitsOnOrder Units On Order 5.75, 0 0.75, 0.19

Adding code to the Windows Form Load event

To write the code in Visual Basic or C#

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

'Visual Basic
Private Sub myForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
     Handles MyBase.Load
   Dim rpt As New rptOne()
   rpt.Run()
   Dim rpt2 As New rptTwo()
   rpt2.Run(
   rpt.Document.Pages.AddRange(rpt2.Document.Pages)
   Viewer1.Document = rpt.Document
   End Sub
   
//C#
private void myForm_Load(object sender, System.EventArgs e)
{
    rptOne rpt1 = new rptOne();
    rpt1.Run();
    rptTwo rpt2 = new rptTwo();	
    rpt2.Run();
    rpt1.Document.Pages.AddRange(rpt2.Document.Pages);
    viewer1.Document = rpt1.Document;
}

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

'Visual Basic
Dim i As Integer
Private Sub myForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
     Handles MyBase.Load
   Dim rpt As New rptOne()
   Viewer1.Document = rpt.Document
   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
End Sub

//C#
int i;
private void myForm_Load(object sender, System.EventArgs e)
{
   rptOne rpt1 = new rptOne();
   Viewer1.Document = rpt.Document
   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]);
   }
}

Viewing the report

To view the report

You can quickly view your report at design time by clicking the Preview tab at the bottom of the designer.

See Also

©2009. All Rights Reserved.