windowsforms-devexpress-dot-xtraeditors-dot-baseedit-387d5c53.md
Enables an appropriate response to be provided when invalid values are entered.
Namespace : DevExpress.XtraEditors
Assembly : DevExpress.XtraEditors.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
[DXCategory("Events")]
public event InvalidValueExceptionEventHandler InvalidValue
<DXCategory("Events")>
Public Event InvalidValue As InvalidValueExceptionEventHandler
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. |
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.
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";
}
Imports DevExpress.XtraEditors.Controls
Private Sub SpinEdit1_Validating(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _
Handles SpinEdit1.Validating
If (TryCast(sender, SpinEdit)).Value >= 100 Then
e.Cancel = True
End If
End Sub
Private Sub SpinEdit1_InvalidValue(ByVal sender As Object, _
ByVal e As DevExpress.XtraEditors.Controls.InvalidValueExceptionEventArgs) _
Handles SpinEdit1.InvalidValue
e.ErrorText = "The value should be less than 100"
End Sub
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.
this.edtEndDate.Validating += new CancelEventHandler(OnEdtEndDateValidating);
this.edtEndDate.InvalidValue += new InvalidValueExceptionEventHandler(OnEdtEndDateInvalidValue);
this.edtEndTime.Validating += new CancelEventHandler(OnEdtEndTimeValidating);
winforms-scheduler-custom-appointment-edit-form/CS/SchedulerDbExample/CustomAppointmentForm.cs#L248
this.edtEndDate.Validating += new CancelEventHandler(OnEdtEndDateValidating);
this.edtEndDate.InvalidValue += new InvalidValueExceptionEventHandler(OnEdtEndDateInvalidValue);
this.edtEndTime.Validating += new CancelEventHandler(OnEdtEndTimeValidating);
AddHandler Me.edtEndDate.Validating, AddressOf OnEdtEndDateValidating
AddHandler Me.edtEndDate.InvalidValue, AddressOf OnEdtEndDateInvalidValue
AddHandler Me.edtEndTime.Validating, AddressOf OnEdtEndTimeValidating
winforms-scheduler-custom-appointment-edit-form/VB/SchedulerDbExample/CustomAppointmentForm.vb#L308
AddHandler edtEndDate.Validating, AddressOf OnEdtEndDateValidating
AddHandler edtEndDate.InvalidValue, AddressOf OnEdtEndDateInvalidValue
AddHandler edtEndTime.Validating, AddressOf OnEdtEndTimeValidating
See Also