BaseEdit.InvalidValue Event
Enables an appropriate response to be provided when invalid values are entered.
Namespace: DevExpress.XtraEditors
Assembly: DevExpress.XtraEditors.v22.2.dll
NuGet Package: DevExpress.Win.Navigation
Declaration
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 provides a number of properties that provide access to details on the exception, allow specifying whether the exception should be raised or not, 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.
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";
}