Glossary Item Box

Samples | Walkthroughs

See Also ActiveReports for .NET 2 Online Help Send feedback to Data Dynamics

Walkthrough: Applying Page Templates

ActiveReports allows you to apply a page template to an existing report by using the Overlay method.

This walkthrough illustrates how to overlay an ActiveReport with a "letterhead" page template.

This walkthrough is split up into the following activities:

To complete the walkthrough, you must have access to the NorthWind database (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. Click on Project > Add New Item.
  3. Select ActiveReports file and rename the file rptReport.
  4. Click Open.
  5. Click on Project > Add New Item.
  6. Select ActiveReports file and rename the file rptTemplate.
  7. Click Open.

Connecting the report to a data source

To connect the report to a data source

  1. Click on the yellow report DataSource icon in the Detail section. This brings up the report DataSource dialog box.
  2. Click on Build...
  3. Select Microsoft Jet 4.0 OLE DB Provider and click Next >>
  4. Click on the ellipsis to browse for the access path to NWind.mdb. Click Open once you have selected the appropriate access path.
  5. Click OK to continue.
  6. In the Query field, type "Select * from customers order by country".
  7. Click OK to return to the report design surface.

Adding controls to display the data

To add controls to the reports

  1. Add a GroupHeader/Footer section to rptReport.
  2. Make the following changes to the group header:
    • Change the name to ghCustomers
    • Change the DataField property to Country
  3. Add the following controls to rptReport, naming them as indicated:

    Control DataField Name Text/Caption Section Location
    Label (Empty string) lblCustomerID Customer ID GroupHeader 0, 0
    Label (Empty string) lblCompanyName Company Name GroupHeader 1.125, 0
    Label (Empty string) lblAddress Address GroupHeader 2.625, 0
    Label (Empty string) lblCity City GroupHeader 4.125, 0
    Label (Empty string) lblCountry Country GroupHeader 5.187, 0
    TextBox CustomerID txtCustomerID Customer ID Detail 0, 0
    TextBox CompanyName txtCompanyName CompanyName Detail 1.125, 0
    TextBox Address txtAddress Address Detail 2.625, 0
    TextBox City txtCity City Detail 4.125, 0
    TextBox Country txtCountry Country Detail 5.187, 0

  4. Add the following controls to rptTemplate, naming them as indicated:

    Control Name Text/Caption Section Location
    TextBox txtCompanyName Company Name PageHeader 0.0625, 0.0625
    Label lblCompanyLogo (Company Logo) PageHeader 4, 0.0625
    Label lblCompanyInfo Company Address, Phone Number, Fax Number, URL PageFooter 0.0625, 0.0625

Adding code to the Form_Load event

To write the code in Visual Basic

Right-click at the top of Form1, and click on View Code to display the code view for the form. At the top left of the code view for Form1, click the drop-down arrow and select (Base Class Events). At the top right of the code window, click the drop-down arrow and select Load. This creates an event-handling method for the Form1_Load event. Add code to the handler to:

To write the code in C#

Click at the top of Form1 to select the form. Click on the events icon in the Properties window to display available events for the form. Double-click Load. This creates an event-handling method for the Form1_Load event. Add code to the handler to:

The following example shows what the code for the Overlay method looks like.

' Visual Basic
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _ MyBase.Load
Dim rpt As New rptReport()
rpt.Run() Dim rpt2 As New rptTemplate()
rpt2.Run()
Viewer1.Document = rpt.Document
For i = 0 To rpt.Document.Pages.Count - 1
rpt.Document.Pages(i).Overlay(rpt2.Document.Pages(0))
Next
End Sub
//C#
private void Form1_Load(object sender, System.EventArgs e)
{
rptReport rpt = new rptReport();
rpt.Run();
rptTemplate rpt2 = new rptTemplate();
rpt2.Run();
viewer1.Document = rpt.Document;
for(int i = 0; i < rpt.Document.Pages.Count; i++)
{
rpt.Document.Pages[i].Overlay(rpt2.Document.Pages[0]);
}
}

Viewing the report

To view the report

  1. Add the ActiveReports viewer control to a Windows Form.
  2. Add the code needed to set the viewer document equal to the report document. See Using the ActiveReports WinForm Viewer for help.

Samples | Walkthroughs

 

 


Copyright © 2004-2005 Data Dynamics, Ltd. All rights reserved.