Create Predefined Static Reports
- 4 minutes to read
This topic describes how to create an XtraReport at Design Time and then register it. An XAF application displays registered reports in the Reports List View. These predefined reports cannot be modified by a user. However, a user can copy a predefined report with the help of the Copy Predefined Report Action and then modify the copy.
Follow the steps below to create an XtraReport and register it for use with the Reports V2 module.
Use the DevExpress v.24.1 Report project item template (see Report Wizard) to add an empty XtraReport to your project. Select the Blank report type and click the Finish button.
The XtraReport1.cs item appears in the module project of your application.
The Reports V2 module supports the following Data Source components to use in XAF-compatible XtraReport classes: CollectionDataSource and ViewDataSource. Drag the CollectionDataSource item from the Toolbox to the created report.
Note
You can use the
ViewDataSource
component instead of theCollectionDataSource
. For more information about the difference between these components refer to the following topic: Data Sources for Reports V2.Invoke the Properties window for the collectionDataSource1 item and set value of the ObjectTypeName property to the name of the business class you want to use for your report.
The business class properties should appear in the Field List window.
Drag the required fields to the report or run the Report Wizard to generate the required layout automatically.
To learn more about report design, refer to the following topics of the Reporting documentation: Report Designer and Report Wizard. Note that the
CollectionDataSource
andViewDataSource
components only provide a list of fields to the designer and you cannot preview the report at design time.Note
- At design time, the Preview tab of the Report Designer is empty. The CollectionDataSource and ViewDataSource components do not connect to a database directly and require an IObjectSpace instance to load data. XAF creates the instance at runtime only, therefore it cannot load data at design time.
- Currently, Custom Fields are not available in the Reports Designer at design time.
After you save the report, register it in your XAF application. Navigate to the ModuleBase.GetModuleUpdaters method in the Module.cs file. Instantiate the PredefinedReportsUpdater class and use the PredefinedReportsUpdater.AddPredefinedReport<T> method to add a report. Add the updater object to the method’s return value.
File: MySolution.Module\Module.cs
// ... using DevExpress.ExpressApp.ReportsV2; using MySolution.Module.BusinessObjects; namespace MySolution.Module; public sealed class MySolutionModule : ModuleBase { public MySolutionModule() { // ... } public override IEnumerable<ModuleUpdater> GetModuleUpdaters( IObjectSpace objectSpace, Version versionFromDB) { ModuleUpdater updater = new DatabaseUpdate.Updater(objectSpace, versionFromDB); PredefinedReportsUpdater predefinedReportsUpdater = new PredefinedReportsUpdater(Application, objectSpace, versionFromDB); predefinedReportsUpdater.AddPredefinedReport<XtraReport1>("Employee DOB Information", typeof(Employee)); return new ModuleUpdater[] { updater, predefinedReportsUpdater }; } // ... }
Note
By default, each new PredefinedReportsUpdater instance removes predefined reports that are not registered within this instance. If you implement your reports in several modules and need to create multiple PredefinedReportsUpdater objects in a single application, set the PredefinedReportsUpdater.UseMultipleUpdaters property of each updater to true.
Run the application. Note that the designed XtraReport is available in the Reports List View. A user can double-click a report to preview it in a Print Preview Form.
- ASP.NET Core Blazor
- Windows Forms
If you want to skip the preview dialog, refer to the How to: Print a Report Without Displaying a Preview example.
Important
When you create a predefined report with scripts that end users can possibly modify, do not use XtraReport events directly. Instead, use the XtraReport.Scripts and/or XRControl.Scripts properties in the Report Designer, as demonstrated in the following topic: Scripting Overview. Otherwise, when you use the Copy Predefined Report Action, XAF does not copy your code to user scripts.
This technique requires that you add references to assemblies used in scripts to the XtraReport.ScriptReferences property. Assemblies used in your application are attached to scripts automatically. If classes from such assemblies cause errors during script evaluation, either use fully qualified names or add the using (Imports in VB) directive at the beginning of the script.