Skip to main content

Invoke the Report Preview from Code

  • 2 minutes to read

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;

// ...
public class MyPrintReportController : ObjectViewController<ListView, Contact> {
    public MyPrintReportController() {
        SimpleAction SalesInvoiceAction = new SimpleAction(this, "Print selected2", PredefinedCategory.RecordEdit);
        SalesInvoiceAction.Execute += SalesInvoiceAction_Execute;

    private void SalesInvoiceAction_Execute(object sender, SimpleActionExecuteEventArgs e) {
        var reportOsProvider = ReportDataProvider.GetReportObjectSpaceProvider(this.Application.ServiceProvider);
        var reportStorage = ReportDataProvider.GetReportStorage(this.Application.ServiceProvider);
        IObjectSpace objectSpace = reportOsProvider.CreateObjectSpace(typeof(ReportDataV2));
        IReportDataV2 reportData = objectSpace.FirstOrDefault<ReportDataV2>(data => data.DisplayName == "Contacts Report");
        string handle = reportStorage.GetReportContainerHandle(reportData);
        ReportServiceController controller = Frame.GetController<ReportServiceController>();
        if(controller != null) {

To filter a report, pass a criterion to the ReportServiceController.ShowPreview method. For example, the following code builds the criterion based on the objects selected in a view:

CriteriaOperator objectsCriteria = ((BaseObjectSpace)objectSpace).GetObjectsCriteria(View.ObjectTypeInfo, e.SelectedObjects);
if(controller != null) {
    controller.ShowPreview(handle, objectsCriteria);

You can use any other criteria here.

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.


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

See Also