Skip to main content

BaseEdit.InvalidValue Event

Enables an appropriate response to be provided when invalid values are entered.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v24.1.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

[DXCategory("Events")]
public event InvalidValueExceptionEventHandler InvalidValue

Event Data

The InvalidValue event's data class is InvalidValueExceptionEventArgs. The following properties provide information specific to this event:

Property Description
ErrorText Gets or sets the error description to be displayed in the message box/tooltip. Inherited from ExceptionEventArgs.
Exception Gets the exception that caused the event. Inherited from ExceptionEventArgs.
ExceptionMode Gets or sets the type of response to supplying invalid values. Inherited from ExceptionEventArgs.
Value Gets an invalid value that caused the exception.
WindowCaption Gets or sets the caption of the error message box. Inherited from ExceptionEventArgs.

Remarks

The InvalidValue event allows the exceptions raised as the result of invalid values being assigned to editors to be handled. Generally, this takes place when an incorrect value type is used or when the editor’s validation fails. Handle this event to perform appropriate exception handling, as shown in the example below. The event parameter includes a number of properties that allow you to obtain the detailed information about the exception, specify whether to raise or suppress the exception, etc.

Example

The following sample code prohibits values greater than 100 being entered into the spin editor. The RepositoryItem.Validating event is handled to check the entered value’s validity. The BaseEdit.InvalidValue event is handled to display an exception hint if an invalid value has been entered.

BaseEdit.InvalidValue

using System.ComponentModel;
using DevExpress.XtraEditors.Controls;

private void spinEdit1_Validating(object sender, CancelEventArgs e) {
   if((sender as SpinEdit).Value >= 100)
      e.Cancel = true;
}
private void spinEdit1_InvalidValue(object sender, InvalidValueExceptionEventArgs e) {
   e.ErrorText = "The value should be less than 100";
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the InvalidValue event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also