XRDesignPanel.OpenReport(String) c#


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

// 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);

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

    // Show the form.
    form.ShowDialog();
    mdiController.ActiveDesignPanel.CloseReport();
}

void mdiController_DesignPanelLoaded(object sender, DesignerLoadedEventArgs e) {
    XRDesignPanel panel = (XRDesignPanel)sender;
    mdiController.AddCommandHandler(new SaveCommandHandler(panel));
}
public class SaveCommandHandler : ICommandHandler {
    XRDesignPanel panel;

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

    public virtual void HandleCommand(ReportCommand command, object[] args, ref bool handled) {
        if (!CanHandleCommand(command)) return;

        // Save a report.
        Save();

        // Set handled to true to avoid the standard saving procedure to be called.
        handled = true;
    }

    public virtual bool CanHandleCommand(ReportCommand command) {
        // This handler is used for SaveFile, SaveFileAs and Closing commands.
        return command == ReportCommand.SaveFile ||
            command == ReportCommand.SaveFileAs ||
            command == ReportCommand.Closing;
    }

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

        // For instance:
        panel.Report.SaveLayout("c:\\report1.repx");

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

Yorumlar