Skip to main content
.NET Framework 4.6.2+

How to: Add a Custom Column to the Reports List

  • 5 minutes to read

This topic describes how to customize the persistent class used to store reports to associate additional information with report objects. For instance, if you add the Category property, an additional column will be added to the Reports List View, and end users will be able to group, sort, or filter by categories.

WinForms
ReportsV2_WizParamsRuntime

ASP.NET Web Forms
ReportsV2_WizParamsRuntime_Web

Blazor
ReportsV2_WizParamsRuntime_Blazor

In this topic, it is assumed that you have an XAF application that uses the Reports V2 Module, and you have created one or more reports (see Reports V2 Module Overview).

Inherit ReportDataV2

Entity Framework Core

If you use Entity Framework Core, create the MyReportDataV2 entity derived from DevExpress.Persistent.BaseImpl.EF.ReportDataV2. Then, add your custom entity to the DbContext.

File: MySolution.Module\BusinessObjects\MyReportDataV2.cs

public class MyReportDataV2 : DevExpress.Persistent.BaseImpl.EF.ReportDataV2 {
    public virtual string Category { get;set; }
}

public class MySolutionDbContext : DbContext {
    // ...
    public DbSet<ReportDataV2> ReportDataV2 { get; set; }
    public DbSet<MyReportDataV2> MyReportDataV2 { get; set; }
}

XPO

If you use XPO, create the MyReportDataV2 persistent class derived from DevExpress.Persistent.BaseImpl.ReportDataV2.

File: MySolution.Module\BusinessObjects\MyReportDataV2.cs

public class MyReportDataV2 : DevExpress.Persistent.BaseImpl.ReportDataV2 {
    public MyReportDataV2(Session session) : base(session) { }
    private string category;
    public string Category {
        get { return category; }
        set { SetPropertyValue(nameof(Category), ref category, value); }
     }
}

Specify ReportsModuleV2.ReportDataType

With Application Builder

In applications that use the Application Builder, assign the type of your custom report data class to the ReportsOptions.ReportDataType property as shown below:

File: MySolution.Blazor.Server\Startup.cs

builder.Modules
    .AddReports(options => {
        options.ReportDataType = typeof(MyReportDataV2);
    })

Without Application Builder

In applications that do not use the Application Builder, you can specify the ReportDataType setting as follows.

File: WinApplication.Designer.cs

partial class MainDemoWinApplication {
    // ...
    private void InitializeComponent() {
        // ...
        // reportsModuleV21
        // 
        this.reportsModuleV21.ReportDataType = typeof(MyReportDataV2);
        // ...
    }
}

In .NET Framework projects, you can alternatively open the Application Designer for the WinApplication.cs (WinApplication.vb) and WebApplication.cs (WebApplication.vb) files and set the ReportsModuleV2.ReportDataType property value to MyReportDataV2.

ReportsV2_ReportDataType

Add the New Property to the Report Wizard

Note

This feature is not supported in ASP.NET Core Blazor. See the Limitations section for more information.

You can also omit this section if you do not want the additional property to be initialized by a user. Instead, you can customize the ReportsStorage class to update the property value in code.

To make the newly introduced property visible in the Report Wizard, do the following.

  • In the platform-agnostic module project, inherit from the NewXafReportWizardParameters class and declare the Category string property.

    File: MySolution.Module\CustomReportWizardParameters.cs

    using DevExpress.ExpressApp.DC;
    using DevExpress.ExpressApp.ReportsV2;
    using DevExpress.ExpressApp.ReportsV2.Win;
    using DevExpress.XtraReports.UI;
    // ...
    [DomainComponent]
    public class CustomReportWizardParameters : NewReportWizardParameters {
        public CustomReportWizardParameters(XtraReport report, Type reportDataType) : 
            base(report, reportDataType) { }
        public string Category { get; set; }
        public override void AssignData(IReportDataV2Writable reportData) {
            base.AssignData(reportData);
            if (reportData is MyReportDataV2) {
                ((MyReportDataV2)reportData).Category = Category;
            }
        }
    }
    
  • In the WinForms application project, implement a View Controller. Override the OnActivated method, access the standard WinReportServiceController and subscribe to its WinReportServiceController.NewXafReportWizardShowing event. In the event handler, pass an instance of the CustomReportWizardParameters class to the Report Wizard.

    File: MySolution.Win\Controllers.ReportWizardModifyController.cs

    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.ReportsV2.Win;
    // ...
    public class ReportWizardModifyController : ViewController {
        WinReportServiceController reportServiceController;
        public ReportWizardModifyController() { }
        protected override void OnActivated() {
            base.OnActivated();
            reportServiceController = Frame.GetController<WinReportServiceController>();
            if (reportServiceController != null) {
                reportServiceController.NewXafReportWizardShowing +=
                    reportServiceController_NewXafReportWizardShowing;
            }
        }
        protected override void OnDeactivated() {
            reportServiceController.NewXafReportWizardShowing -=
                reportServiceController_NewXafReportWizardShowing;
            reportServiceController = null;
            base.OnDeactivated();
        }
        void reportServiceController_NewXafReportWizardShowing(object sender,
            NewXafReportWizardShowingEventArgs e) {
            if (!e.ReportDataType.Equals(typeof(MyReportDataV2))) return;
            CustomReportWizardParameters newReportParamsObject = new
                CustomReportWizardParameters(e.WizardParameters.Report, e.WizardParameters.ReportDataType);
            newReportParamsObject.Category = "Default";
            e.WizardParameters = newReportParamsObject;
        }
    }
    
  • In the ASP.NET Web Forms module project, implement one more View Controller. Analogously, override the OnActivated method, access the standard WebReportServiceController and subscribe to its WebReportServiceController.NewReportWizardShowing event. In the event handler, pass an instance of the CustomReportWizardParameters class to the Report Wizard.

    File: MySolution.Web.Module\Controllers.ReportWizardModifyController.cs

    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.ReportsV2.Web;
    // ...
    public class ReportWizardModifyController : ViewController {
        WebReportServiceController reportServiceController;
        public ReportWizardModifyController() { }
        protected override void OnActivated() {
            base.OnActivated();
            reportServiceController = Frame.GetController<WebReportServiceController>();
            if (reportServiceController != null) {
                reportServiceController.NewReportWizardShowing +=
                    reportServiceController_NewReportWizardShowing;
            }
        }
        protected override void OnDeactivated() {
            reportServiceController.NewReportWizardShowing -=
                reportServiceController_NewReportWizardShowing;
            reportServiceController = null;
            base.OnDeactivated();
        }
        void reportServiceController_NewReportWizardShowing(object sender,
            WebNewReportWizardShowingEventArgs e) {
            if (!e.ReportDataType.Equals(typeof(MyReportDataV2))) return;
            CustomReportWizardParameters newReportParamsObject = new
                CustomReportWizardParameters(e.WizardParameters.Report, e.WizardParameters.ReportDataType);
            newReportParamsObject.Category = "Default";
            e.WizardParameters = newReportParamsObject;
        }
    }
    
  • In the ASP.NET Core Blazor application project, implement one more View Controller. Similarly, override the OnActivated method, access the standard DevExpress.ExpressApp.ReportsV2.Blazor.BlazorReportServiceController, and subscribe to its BlazorReportServiceController.NewReportWizardShowing event. In the event handler, pass an instance of the CustomReportWizardParameters class to the Report Wizard.

    File: MySolution.Blazor.Server\Controllers.ReportWizardModifyController.cs

    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.ReportsV2.Blazor;
    // ...
    public class ReportWizardModifyController : ViewController {
        BlazorReportServiceController reportServiceController;
        public ReportWizardModifyController() { }
        protected override void OnActivated() {
            base.OnActivated();
            reportServiceController = Frame.GetController<BlazorReportServiceController>();
            if(reportServiceController != null) {
                reportServiceController.NewReportWizardShowing += ReportServiceController_NewReportWizardShowing;
            }
        }
        private void ReportServiceController_NewReportWizardShowing(object sender, BlazorNewReportWizardShowingEventArgs e) {
            if(!e.ReportDataType.Equals(typeof(MyReportDataV2)))
                return;
            CustomReportWizardParameters newReportParamsObject = 
            new CustomReportWizardParameters(e.WizardParameters.Report, e.WizardParameters.ReportDataType);
            newReportParamsObject.Category = "Default";
            e.WizardParameters = newReportParamsObject;
        }
        protected override void OnDeactivated() {
            reportServiceController.NewReportWizardShowing -= ReportServiceController_NewReportWizardShowing;
            reportServiceController = null;
            base.OnDeactivated();
        }
    }
    

After you complete these steps, the following Detail Views are added to the Application Model:

  • MyReportData_DetailView
  • CustomReportWizardParameters_DetailView

To place the new Category item at the desired position, start the Model Editor and adjust these Detail View layouts.

ReportsV2_WizParams

For a detailed explanation of how to customize a Detail View’s layout, refer to the View Items Layout Customization help topic.

Limitations

XAF does not support the capability to display and edit custom report properties in the New Report Wizard under the ASP.NET Core Blazor platform. An end user can use the Report ListView’s Edit action to specify a custom property value:

Edit Custom Report Properties