Skip to main content

XRDesignPanel.OpenReport(Stream) Method

Loads a report definition from the specified stream and opens it in the XRDesignPanel.

Namespace: DevExpress.XtraReports.UserDesigner

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

NuGet Package: DevExpress.Win.Reporting

Declaration

public void OpenReport(
    Stream stream
)

Parameters

Name Type Description
stream Stream

A Stream object which contains a report to be opened in the design panel.

Remarks

This method loads a report definition from a REPX format stored in a stream in the same way as the XtraReport.LoadLayout method does. If the specified stream doesn’t contain a report, or the REPX format is corrupted, then the DevExpress.XtraReports.Serialization.XRSerializationException will be raised.

Note

Make sure that you call the XRDesignPanel.CloseReport method after report editing is finished. This is especially necessary before previewing or exporting a report, or you will get the InvalidOperationException error: “This method call is invalid for the object’s current state”.

To learn more, refer to Storing Report Layouts.

Example

This example shows how to override the SaveFile and OpenFile commands in the End-User Report Designer.

using System;
using System.Windows.Forms;
using DevExpress.XtraReports.UserDesigner;

namespace CustomSavingEUD {
    public partial class Form1 : Form
    {
        public Form1() {
            InitializeComponent();
        }

        // Create an MDI (multi-document interface) controller instance.
        XRDesignMdiController mdiController;

        private void button1_Click(object sender, EventArgs e) {
            // Create a design form and get its MDI controller.
            XRDesignForm form = new XRDesignForm();
            mdiController = form.DesignMdiController;

            // Handle the DesignPanelLoaded event of the MDI controller,
            // to override the SaveCommandHandler for every loaded report.
            mdiController.DesignPanelLoaded +=
                new DesignerLoadedEventHandler(mdiController_DesignPanelLoaded);

            // Override the Open Command.
            mdiController.AddCommandHandler(new OpenCommandHandler());

            // Open an empty report in the form.
            mdiController.OpenReport(new XtraReport1());

            // Show the form.
            form.ShowDialog();
            if (mdiController.ActiveDesignPanel != null) {
                mdiController.ActiveDesignPanel.CloseReport();
            }
        }
        void mdiController_DesignPanelLoaded(object sender, DesignerLoadedEventArgs e) {
            XRDesignPanel panel = (XRDesignPanel)sender;
            // Override the Save Command.
            panel.AddCommandHandler(new SaveCommandHandler(panel));
        }
    }
}

The following code shows the Save and Open command handlers that implement the ICommandHandler interface:

using DevExpress.XtraReports.UserDesigner;
public class SaveCommandHandler : ICommandHandler {
    XRDesignPanel panel;

    public SaveCommandHandler(XRDesignPanel panel) {
        this.panel = panel;
    }

    public void HandleCommand(ReportCommand command,
    object[] args) {
        // Save the report.
        Save();
    }

    public bool CanHandleCommand(ReportCommand command,
    ref bool useNextHandler) {
        useNextHandler = !(command == ReportCommand.SaveFile ||
            command == ReportCommand.SaveFileAs);
        return !useNextHandler;
    }

    void Save() {
        // Write your custom method here.
        // ...

        // Example:
        panel.Report.SaveLayout("report1.repx");

        // Prevent the "Report has been changed" dialog from being shown.
        panel.ReportState = ReportState.Saved;
    }
}

For information on how to customize the WinForms End-User Report Designer, review the following help topic: WinForms End-User Report Designer API and Customization.

See Also