ActiveReports 6 Online Help
Create Report Templates (Inheritance)
Show AllShow All
Hide AllHide All

You can create a base report class as a template from which other reports can inherit. This is useful when many of your reports share common features, such as identical page headers and footers. Instead of recreating the look every time, create template headers and footers once and use inheritance to apply them to your other reports.

In ActiveReports, you can use inheritance at both design time and run time. A simple example of how you can use this functionality is a company letterhead template.

To create a company letterhead template at design time

  1. Add an ActiveReport to your Visual Studio project and name the file rptLetterhead. This is the base report class.
  2. Drag the following controls from the ActiveReports toolbox to the indicated section of rptLetterhead and set the properties as indicated. Reports do not inherit from the detail section, so do not add controls to it.

    Controls for rptLetterhead

  3. Click in the grey area below the report to select it, and in the Properties window, set the MasterReport property to True.
    Important: Do not set the MasterReport property to True until you have finished making changes to the report. Setting this property to True triggers major changes in the designer file for the report.
  4. The detail section of the report is disabled. When you create reports that inherit from this class, they will provide the detail section.
  5. Add a second ActiveReport to your project and name the file rptLetter. This report will inherit its PageHeader and PageFooter sections from rptLetterhead.
  6. In the Solution Explorer tool strip, click the Show All Files button.
  7. Expand the rptLetter node and double-click to open the rptLetter.Designer file (in a C# project, right-click the rptLetter.cs node and select View Code to display the code view for the report).
  8. In the rptLetter.Designer code (in a C# project, in the rptLetter code), change the inheritance statement so that rptLetter inherits from rptLetterhead instead of from DataDynamics.ActiveReports.ActiveReport. Use code like the following:

    To write the code in Visual Basic.NET

    To write the code in C#

  9. Close the reports and from the Build menu, select Rebuild. When you reopen rptLetter, the inherited sections and controls are disabled.
    Note: To make changes in these sections in rptLetterhead and rebuild your project again.
  10. Add data and controls to the detail section of the report as you would any other report. See the Basic Data Bound Reports walkthrough for more information.

Caution: Base reports and the reports that inherit from them cannot contain controls with duplicate names. You can compile and run your project with duplicate control names, but you cannot save the layout until the duplicate names are changed.
See Also

Walkthroughs