Invoke the Report Preview from Code

This topic describes how you can display the preview of a specific IReportDataV2 object from a custom Controller code.

The ReportServiceController provides the ReportServiceController.ShowPreview method you can call to invoke the report preview window. The code below demonstrates how to use this method.

using DevExpress.ExpressApp.ReportsV2;
using DevExpress.Persistent.Base;

// Uncomment this line in XPO-based application:
// using DevExpress.Persistent.BaseImpl;

// Uncomment this line in EF-based application:
// using DevExpress.Persistent.BaseImpl.EF;

// ...
IObjectSpace objectSpace = 
    ReportDataProvider.ReportObjectSpaceProvider.CreateObjectSpace(typeof(ReportDataV2));
IReportDataV2 reportData = 
    objectSpace.FindObject<ReportDataV2>(
    CriteriaOperator.Parse("[DisplayName] = 'Contacts Report'"));
string handle = ReportDataProvider.ReportsStorage.GetReportContainerHandle(reportData);
ReportServiceController controller = Frame.GetController<ReportServiceController>();
if (controller != null) {
    controller.ShowPreview(handle);
}

In the criteria string used in the code above, substitute "Contacts Report" with the actual IReportDataV2.DisplayName value of the report you want to display.

Tip

Optionally, you can filter and sort data displayed in report using the criteria and sortProperty parameters of the ShowPreview method.

See Also