Skip to main content

XRDesignPanel.RemoveCommandHandler(ICommandHandler) Method

Removes the specified command handler.

Namespace: DevExpress.XtraReports.UserDesigner

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

NuGet Package: DevExpress.Win.Reporting

Declaration

public void RemoveCommandHandler(
    ICommandHandler handler
)

Parameters

Name Type Description
handler ICommandHandler

The command handler to be removed.

Remarks

Call the RemoveCommandHandler method to remove a command handler that is assigned to a report command.

Note

The RemoveCommandHandler method is available only in Windows Forms applications.

Report commands are listed in the ReportCommand enumeration. To add a custom command handler to one or several report commands, call the XRDesignPanel.AddCommandHandler method.

Example

The code sample below demonstrates how to use the RemoveCommandHandler method to remove the Save command’s custom handler.

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

namespace CodeSnippets.XRDesignPanel_AddRemoveCommandHandlers
{
    public class ReportTester
    {
        XRDesignMdiController mdiController;

        private void CustomReportDesigner()
        {
            // 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 XtraReport());

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

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

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

        public void HandleCommand(DevExpress.XtraReports.UserDesigner.ReportCommand command, object[] args)
        {
            if (MessageBox.Show("Please enter your license key to be able to save the report.", "caption", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                // Write your code to enter a license key.

                // Remove this command handler if the license key is entered.
                panel.RemoveCommandHandler(this);
            }
        }

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