Skip to main content

Create an Inherited Report

  • 4 minutes to read

This tutorial describes how to make a newly created report inherit its settings from an existing XtraReport at design time within Visual Studio.

Create a Reporting Application

Create a reporting application. To learn how to create a reporting application on the platform of your choice, see Adding a Report to Your .NET Application.

Although this tutorial is based on Windows Forms, the same steps apply for inheriting reports on any other supported platform.

Create a Base Report

The visual inheritance of reports is similar to that of Windows Forms. It allows you to create a base report, and then inherit from it and make modifications in descendant reports, while preserving the layout and settings of the original report. For more information about visual inheritance, refer to the following article: Windows Forms Visual Inheritance.

To create a parent report, whose layout will be inherited by all descendants, do the following:

  1. Define a layout for the default parent report. For example, create a simple static report by adding an XRLabel to its detail band. All future reports should inherit this basic layout.

    The label created in the base report will be available in all inherited reports. To permit changes in an individual label’s properties (independent of the base report), set the control’s Modifiers property to Protected, Protected Internal or Public.

    inheritedReport2

    The exact setting of the Modifiers property depends on your application requirements. TFor more information about access modifiers in .NET, review the following topics: Access Modifiers (C# Programming Guide) and Access Levels in Visual Basic.

    Set this property for every object that you wish to modify in inherited reports.

  2. Before proceeding with the following steps, rebuild your application by clicking BUILD | Rebuild Solution in the main menu in Visual Studio. This will generate the application’s assembly (.exe or .dll) file containing the base report class, and the inherited reports will gain access to the base report at design time.

    Shared_RebuildSolution

Create an Inherited Report

To add a new inherited report to an application, do the following.

  1. In Visual Studio, press CTRL+SHIFT+A or click PROJECT | Add New Item… in the main menu.
  2. In the Add New Item dialog that is invoked, switch to the Reporting directory and select DevExpress v24.2 Report item.

  3. Next, in the invoked Report Wizard, choose Inherited Report and click Next.

    ReportWizard-ChooseReportType-InheritedReport

  4. On the next wizard page, select an ancestor report from the list of available reports and click Finish. Now, a new report inherits its layout from this report.

    how-to-create-an-inherited-report-0

    Alternatively, you can select the ancestor report that is contained in a separate assembly. To do this, click Select the assembly that contains ancestor reports and, in the invoked Open Assembly dialog, select the required assembly.

    how-to-create-an-inherited-report-1

Editing of the created inherited report will be prohibited unless this is allowed by the Modifiers property setting of the ancestor report.

Create an Inherited Report in .NET Applications

In .NET projects, the Report Wizard does not have the Inherited Report option. To create an inherited report, create a report class in code and derive it from a base report class.

The base report must define a public constructor with the InitializeComponent method. If you make any layout changes for the inherited report, the report designer generates the InitializeComponent method for the inherited report. The inherited report has to define a public constructor with the InitializeComponent method as well.

Base Report:

public class BaseReport : XtraReport {
    public BaseReport() {
        InitializeComponent();
    }
}

Inherited Report:

public class InheritedReport : BaseReport {
    public InheritedReport(){
        InitializeComponent()
    }
    // ...
}

Customize the Inherited Report

After adding the inherited report, you can add new elements to it (bands and controls), and modify the inherited elements that were made public.

inheritedReport5

When you change the property values of inherited controls, these properties are overridden in the inherited report.

To obtain the value of a property from the base report, reset this property value. To do this, select the control and locate the required property (for example, ForeColor) in the Properties window. Right-click this property and select Reset.

inheritedReport6