Skip to main content
All docs
V24.1

ReportWizardCustomizationService.TryCreateCustomReportAsync(XtraReportModel, Object, String, CustomWizardData, XtraReport) Method

Allows you to create any type of report and apply all settings specified in the wizard steps, asynchronously.

Namespace: DevExpress.XtraReports.Web.ReportDesigner.Services

Assembly: DevExpress.XtraReports.v24.1.Web.dll

NuGet Package: DevExpress.Web.Reporting.Common

Declaration

public virtual Task<XtraReport> TryCreateCustomReportAsync(
    XtraReportModel model,
    object dataSource,
    string dataMember,
    CustomWizardData customWizardData,
    XtraReport report
)

Parameters

Name Type Description
model XtraReportModel

An object that stores settings specified using the wizard.

dataSource Object

A data source specified with the wizard.

dataMember String

The data member value specified using the wizard.

customWizardData CustomWizardData

Additional data specified using the wizard.

report XtraReport

A report instance with which the Wizard starts.

Returns

Type Description
Task<XtraReport>

A Task that completes when the method is finished.

Remarks

The TryCreateCustomReportAsync method is called in asynchronous mode, after a user has completed the Wizard. Within the method, you can create any type of report and apply all settings specified using the wizard steps. Report settings are included in the wizard report model (passed to the method with the model parameter).

The TryCreateCustomReportAsync method is also called when the user runs the New command in the Report Designer or invokes the Report Wizard.

Note that you can either change the initial report from which the Wizard starts, or create a new report from scratch.

The following code snippet removes the Cross-Tab report from the wizard and adds three ReportWizardTemplate items to the collection. After the Wizard is finished, it adds a simple report header to the created report.

Note that you should handle the ID of the custom report template item in the TryCreateCustomReport method, so that the user can create custom reports from that template.

using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Web.ReportDesigner.DataContracts;
using DevExpress.XtraReports.Web.ReportDesigner.Services;
using DevExpress.XtraReports.Wizards;
using ReportWizardCustomizationServiceMvcExample.PredefinedReports;
using System;
using System.Linq;
using System.Threading.Tasks;

public class InstantReportWizardCustomizationService : ReportWizardCustomizationService {
    public enum CustomReportType {
        CustomLabelReport,
        InstantReport
    }

    public override XtraReport TryCreateCustomReport(XtraReportModel model, object dataSource, string dataMember, CustomWizardData customWizardData, XtraReport report) {
        if (Enum.TryParse(customWizardData.ReportTemplateID, out CustomReportType customReportType)) {
            if (customReportType == CustomReportType.InstantReport) {
                return new InstantReport() {
                    Name = customWizardData.ReportTemplateID,
                    DisplayName = customWizardData.ReportTemplateID
                };
            }
            else if (customReportType == CustomReportType.CustomLabelReport) {
                var labelReport = new LabelReport();
                labelReport.ApplyCustomData(customWizardData.Data);
                return labelReport;
            }
        }
        return base.TryCreateCustomReport(model, dataSource, dataMember, customWizardData, report);
    }
    public override Task<XtraReport> TryCreateCustomReportAsync(XtraReportModel model, object dataSource, string dataMember, CustomWizardData customWizardData, XtraReport report) {
        return Task.FromResult(TryCreateCustomReport(model, dataSource, dataMember, customWizardData, report));
    }
    public override void CustomizeReportTypeList(ReportWizardTemplateCollection predefinedTypes) {
        predefinedTypes.Remove(predefinedTypes.Where(x => x.ID == nameof(ReportType.CrossTab)).First());
        predefinedTypes.Add(new DevExpress.XtraReports.Web.ReportDesigner.DataContracts.ReportWizardTemplate() {
            CanInstantlyFinish = true,
            ID = nameof(CustomReportType.InstantReport),
            Text = "Instant Report",
            ImageTemplateName = "instant-report"
        });
        predefinedTypes.Add(new DevExpress.XtraReports.Web.ReportDesigner.DataContracts.ReportWizardTemplate() {
            CanInstantlyFinish = true,
            ID = nameof(CustomReportType.InstantReport),
            Text = "Instant Report",
            ImageClassName = "instant-report-image"
        });
        predefinedTypes.Add(new DevExpress.XtraReports.Web.ReportDesigner.DataContracts.ReportWizardTemplate() {
            ID = nameof(CustomReportType.CustomLabelReport),
            Text = "Custom Label Report",
            ImageTemplateName = "dxrd-svg-wizard-LabelReport"
        });
    }

    public override Task CustomizeReportTypeListAsync(ReportWizardTemplateCollection predefinedTypes) {
        CustomizeReportTypeList(predefinedTypes);
        return Task.CompletedTask;
    }

    public override void CustomizeReportOnFinish(XtraReport report) {
        if (report.Bands.GetBandByType(typeof(ReportHeaderBand)) == null)
            report.Bands.Add(new ReportHeaderBand() {
                Controls = {
                    new XRLabel() {
                        Text = string.Format("Instant Report {0:MMM dd}", System.DateTime.Today),
                        SizeF= new System.Drawing.SizeF(650F, 100F),
                        Font = new DevExpress.Drawing.DXFont("Arial", 24)

    } }
            }); ; ;
    }

    public override Task CustomizeReportOnFinishAsync(XtraReport report) {
        CustomizeReportOnFinish(report);
        return Task.CompletedTask;
    }
}

For more information on asynchronous mode, review the following help topics:

ASP.NET Core ASP.NET MVC
ReportingConfigurationBuilder.UseAsyncEngine DefaultReportDesignerContainer.UseAsyncEngine
See Also