Skip to main content

How to: Customize Report Parameter Editors in a Report Viewer

  • 3 minutes to read

This topic explains how to customize the control used to edit a report parameter value in a Report Viewer.

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

Customize Parameter Editor (Blazor)

Create a View Controller and handle the CustomizeViewItemControl method. In the handler, access the ReportViewerModel and use its API to access and customize parameter editors.

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.ReportsV2.Blazor;

namespace SolutionName.Module.Blazor.Controllers {
public class CustomizeReportParameterEditorsController :ViewController<DetailView> {
    public CustomizeReportParameterEditorsController() {
        TargetViewId = ReportsBlazorModuleV2.ReportViewerDetailViewName;
    }
    protected override void OnActivated() {
        base.OnActivated();
        View.CustomizeViewItemControl<ReportViewerViewItem>(this, CustomizeReportViewer);
    }
    private void CustomizeReportViewer(ReportViewerViewItem reportViewerViewItem) {
        reportViewerViewItem.ReportViewerModel.OnCustomizeParameters = EventCallback.Factory.Create<ParametersModel>(this, CustomizeParameters);
    }
    private void CustomizeParameters(ParametersModel parametersModel) {
        // Customize parameter editors here
    }

}

Custom Parameter Editor for Standard .NET Types (WinForms)

To provide a custom editor for parameters of a standard type in a Windows Forms application, handle the XtraReport.ParametersRequestBeforeShow event, and assign the custom editor to the ParameterInfo.Editor property of the ParameterInfo object stored in the ParametersRequestEventArgs.ParametersInformation collection. To get an XtraReport instance, handle the ReportDataSourceHelper.BeforeShowPreview event.

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.ReportsV2;
using DevExpress.XtraEditors;
using DevExpress.XtraReports.Parameters;
// ...
public class WinModule : ModuleBase {
    public override void Setup(ApplicationModulesManager moduleManager) {
        base.Setup(moduleManager);
        ReportsModuleV2 module = ReportsModuleV2.FindReportsModule(moduleManager.Modules);
        if(module != null) {
            module.ReportsDataSourceHelper.BeforeShowPreview += ReportsDataSourceHelper_BeforeShowPreview;
        }
    }
    private void ReportsDataSourceHelper_BeforeShowPreview(object sender, BeforeShowPreviewEventArgs e) {
        e.Report.ParametersRequestBeforeShow += (s, arg) => {
            foreach(ParameterInfo info in arg.ParametersInformation) {
                if(info.Parameter.Name == "parameter1") {
                    LookUpEdit lookUpEdit = new LookUpEdit();
                    lookUpEdit.Properties.DataSource = new List<string>(new string[] { "One", "Two"});
                    info.Editor = lookUpEdit;
                }
            }
        };
    }
}

Custom Parameter Editor for Custom Types (WinForms)

Handle the static ReportsWindowsFormsModuleV2.CreateCustomReportDesignRepositoryItem event to specify a custom RepositoryItem used to edit a parameter value when a report is being previewed. Pass your repository item using the handler’s CreateCustomReportDesignRepositoryItemEventArgs.RepositoryItem parameter and set the Handled parameter to true. The specified control will be used for any report in the application.

As the CreateCustomReportDesignRepositoryItem is static, which means that you can access it anywhere in your WinForms project. For instance, you can subscribe to the CreateCustomReportDesignRepositoryItem in the overridden ModuleBase.Setup method of a WinForms module (in the WinModule.cs file).

using DevExpress.XtraEditors.Repository;    
using DevExpress.ExpressApp.ReportsV2.Win;
// ...

public override void Setup(XafApplication application) {
    base.Setup(application);
    ReportsWindowsFormsModuleV2.CreateCustomReportDesignRepositoryItem += 
        delegate(object sender, CreateCustomReportDesignRepositoryItemEventArgs e) {
        if(e.Parameter.Name.Equals("parameterTitle")) {
            RepositoryItemLookUpEdit item = new RepositoryItemLookUpEdit();
            item.NullText = "[Select Title Of Courtesy]";
            List<TitleOfCourtesy> st = new List<TitleOfCourtesy>();
            st.Add(TitleOfCourtesy.Dr);
            st.Add(TitleOfCourtesy.Mrs);
            item.DataSource = st;
            e.RepositoryItem = item;
            e.Handled = true;
        }
    };
}
See Also