The requested page is not available for the requested platform. You are viewing the content for Default platform.

How to: Add a Custom Column to the Reports List

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

WinForms:

ReportsV2_WizParamsRuntime

ASP.NET:

ReportsV2_WizParamsRuntime_Web

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).

Note

Mobile applications do not support the Report Wizard, so the approach described in this topic cannot be implemented in the Mobile platform.

Tip

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T154234.

Inherit ReportDataV2

Entity Framework

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

public class MyReportDataV2 : DevExpress.Persistent.BaseImpl.EF.ReportDataV2 {
    public 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.

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

Specify ReportsModuleV2.ReportDataType

In the Application Designer, set the ReportsModuleV2.ReportDataType property value to MyReportDataV2.

ReportsV2_ReportDataType

Repeat this step for both the WinApplication.cs (WinApplication.vb) and WebApplication.cs (WebApplication.vb) files.

Add the New Property to the Report Wizard

Note

You can 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.

    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 module 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.

    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 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.

    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;
        }
    }
    

The following Detail Views are added to the Application Model after performing the steps above.

  • 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.