The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.0+

How to: Use the Custom Report Preview Form

  • 2 min to read

This example demonstrates how to show a custom Report Preview form by handling the ReportServiceController.CustomShowPreview event.

Note

Mobile applications do not support the report preview mechanism, so the approach described in this topic cannot be implemented in the Mobile platform.

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

Use the following Controller to display a report preview in a custom window (the CustomPreviewForm form, in this example).

using DevExpress.XtraReports.UI;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.ReportsV2;
// ...
public class CustomPreviewController : ViewController {
    private ReportServiceController reportServiceController;
    protected override void OnActivated() {
        base.OnActivated();
        reportServiceController = Frame.GetController<ReportServiceController>();
        if (reportServiceController != null) {
            reportServiceController.CustomShowPreview += reportServiceController_CustomShowPreview;
        }
    }
    void reportServiceController_CustomShowPreview(object sender, CustomShowPreviewEventArgs e) {
        IReportContainer reportContainer = 
            ReportDataProvider.ReportsStorage.GetReportContainerByHandle(e.ReportContainerHandle);
        reportServiceController.SetupBeforePrint(reportContainer.Report, 
            e.ParametersObject, e.Criteria, e.CanApplyCriteria, e.SortProperty, e.CanApplySortProperty);
        CustomPreviewForm form = new CustomPreviewForm();
        form.ShowReport(reportContainer.Report);
        e.Handled = true;
    }
    protected override void OnDeactivated() {
        if (reportServiceController != null) {
            reportServiceController.CustomShowPreview -= reportServiceController_CustomShowPreview;
        }
    }
}

The CustomPreviewForm form can be designed as described in the following tutorials:

When the CustomPreviewForm is ready, add the ShowReport method to it.

public void ShowReport(XtraReport report){
    documentViewer1.DocumentSource = report;
    report.CreateDocument();
    Show();
}

In this example, documentViewer1 is the DocumentViewer component added to the current form.

Tip

Refer to the API and Customization section in the XtraReports documentation to learn more about report preview customization.