A newer version of this page is available. Switch to the current version.

BaseEdit.Validate Event

Enables you to validate the editor's value.

Namespace: DevExpress.Xpf.Editors

Assembly: DevExpress.Xpf.Core.v19.1.dll

Declaration

public event ValidateEventHandler Validate
Public Event Validate As ValidateEventHandler

Event Data

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

Property Description
Culture Gets the culture related to the validation.
ErrorContent Gets or sets an object that describes the validation error.
ErrorType Gets or sets the error type.
Handled Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. Inherited from RoutedEventArgs.
IsValid Gets or sets a value specifying whether the value is valid.
OriginalSource Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs.
RoutedEvent Gets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs.
Source Gets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs.
UpdateSource Gets the action that caused the validation.
Value Gets the editor's value.

The event data class exposes the following methods:

Method Description
InvokeEventHandler(Delegate, Object) When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation. Inherited from RoutedEventArgs.
OnSetSource(Object) When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. Inherited from RoutedEventArgs.
SetError(Object) Displays an error within the editor.
SetError(Object, ErrorType) Displays an error within the editor.

Remarks

Handle the Validate event to manually validate the editor (e.g. to limit the range of valid values, implement a custom conditional validation mechanism, etc).

To specify when the editor should automatically validate its value, use the BaseEdit.ValidateOnEnterKeyPressed and BaseEdit.ValidateOnTextInput properties. To manually force the editor's validation, call the BaseEdit.DoValidate method.

NOTE

The Validate event is not raised if the editor's BaseEdit.CausesValidation property is set to false.

To learn more, see Input Validation.

Examples

The following example shows how to handle the BaseEdit.Validate event to provide a custom validation procedure.

The image below shows the result:

exDataValidation

private void dxTextEdit_Validate(object sender, DevExpress.Xpf.Editors.ValidationEventArgs e) {
    if (e.Value == null) return;
    if (e.Value.ToString().Length > 4) return;
    e.IsValid = false;
    e.ErrorType = DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information;
    e.ErrorContent = "User ID is less than five symbols. Please correct.";
}
See Also