How to: Use the Custom Report Preview Form
- 2 minutes to read
This example demonstrates how to show a custom Report Preview form in a WinForms XAF application that uses the Reports V2 Module.
In the WinForms Module project (MySolution.Module.Win), create a new custom form (CustomPreviewForm in this example) and design it as described in the following help topic: Create a Custom Print Preview.
Tip
Refer to the API and Customization section in the XtraReports documentation to learn more about report preview customization.
Add the ShowReport method to CustomPreviewForm:
File: MySolution.Module.Win\CustomPreviewForm.cs(.vb).
using DevExpress.XtraReports.UI; using System.Windows.Forms; // ... public partial class CustomPreviewForm : Form { // ... public void ShowReport(XtraReport report){ documentViewer1.DocumentSource = report; report.CreateDocument(); Show(); } }
In this example, documentViewer1 is the DocumentViewer component added to this form in the previous step.
In the WinForms Module project (MySolution.Module.Win), create the following Controller to display a report preview in the CustomPreviewForm form:
File: MySolution.Module.Win\Controllers\CustomPreviewController.cs(.vb).
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; } } }