Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

IMessageBoxService Interface

In This Article

A service that enables you to display a custom message box when a runtime error occurs.

Namespace: DevExpress.XtraSpreadsheet.Services

Assembly: DevExpress.Spreadsheet.v24.2.Core.dll

NuGet Package: DevExpress.Spreadsheet.Core

#Declaration

public interface IMessageBoxService

#Remarks

The example below shows how to create and register a custom service. Create a class that implements the IMessageBoxService interface and use the SpreadsheetControl.ReplaceService<T> method to register the custom service instead of the default one.

MyMessageBoxService svc = new MyMessageBoxService(spreadsheetControl1, spreadsheetControl1.LookAndFeel);
spreadsheetControl1.ReplaceService<DevExpress.XtraSpreadsheet.Services.IMessageBoxService>(svc);
using System.Windows.Forms;
using DevExpress.LookAndFeel;
using DevExpress.XtraEditors;
using DevExpress.Spreadsheet;
using DevExpress.Portable;
// ...

class MyMessageBoxService : DevExpress.XtraSpreadsheet.Services.IMessageBoxService
    {
        readonly Control control;
        readonly UserLookAndFeel lookAndFeel;

        public MyMessageBoxService(Control control, UserLookAndFeel lookAndFeel)
        {
            this.control = control;
            this.lookAndFeel = lookAndFeel;
        }

        // To test: select a range of cells with and without data validation settings
        // and click Data Validation command to invoke the Data Validation dialog.
        public PortableDialogResult ShowYesNoCancelMessage(string message) {
            string myMessage = "Aktion auswählen\n\n" + message;
            return (PortableDialogResult)XtraMessageBox.Show(lookAndFeel, control, myMessage, Application.ProductName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
        }

        // To test: enter incorrect data into a cell with a data validation rule applied.
        public PortableDialogResult ShowDataValidationDialog(string message, string title, DataValidationErrorStyle errorStyle) {
            string myMessage = "Der eingegebene Wert ist ungültig.\n\n" + message;
            MessageBoxButtons buttons;
            MessageBoxIcon icon;
            if(errorStyle == DataValidationErrorStyle.Stop) {
                buttons = MessageBoxButtons.RetryCancel;
                icon = MessageBoxIcon.Error;
            } else if(errorStyle == DataValidationErrorStyle.Warning) {
                buttons = MessageBoxButtons.YesNoCancel;
                icon = MessageBoxIcon.Warning;
            } else {
                buttons = MessageBoxButtons.OKCancel;
                icon = MessageBoxIcon.Information;
            }
            return (PortableDialogResult)XtraMessageBox.Show(lookAndFeel, control, myMessage, title, buttons, icon);
        }

        // To test: click the Test button or try to set the row height to 1000.
        public PortableDialogResult ShowMessage(string message, string title, PortableMessageBoxIcon icon) {
            string myMessage = "Ein Fehler tritt auf.\n\n" + message;
            var myIcon = (MessageBoxIcon)icon;
            return (PortableDialogResult)XtraMessageBox.Show(lookAndFeel, control, myMessage, title, MessageBoxButtons.OK, myIcon);
        }

        // To test: drag and drop cells to another location trying to overwrite the content of the destination cells.
        public bool ShowOkCancelMessage(string message)
        {
            string myMessage = "Möchten Sie diesen Vorgang wirklich ausführen?\n\n" + message;
            return PortableDialogResult.OK == (PortableDialogResult)XtraMessageBox.Show(lookAndFeel, control, myMessage, Application.ProductName, MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
        }

        // To test: try to delete a defined name in the Name Manager dialog.
        public bool ShowYesNoMessage(string message)
        {
            string myMessage = "Entscheidung treffen. Ja oder Nein?\n\n" + message;
            return PortableDialogResult.Yes == (PortableDialogResult)XtraMessageBox.Show(lookAndFeel, control, myMessage, Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
        }
    }
See Also