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

ValidationEventArgs.SetError(Object, ErrorType) Method

Marks the processed input value as invalid and displays an error within the editor with the specified error icon type.

Namespace: DevExpress.Xpf.Editors

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

NuGet Package: DevExpress.Wpf.Core

#Declaration

public void SetError(
    object errorContent,
    ErrorType errorType
)

#Parameters

Name Type Description
errorContent Object

An object that specifies the error content.

errorType ErrorType

One of the ErrorType enumeration values.

#Remarks

The SetError method automatically sets the ValidationEventArgs.IsValid property to false. If the errorContent parameter is set to an empty string or null, the ValidationEventArgs.IsValid property is set to true and the error isn’t displayed.

using System;
using DevExpress.Xpf.Editors;
using DevExpress.XtraEditors.DXErrorProvider;
//...
private void textEdit_Validate(object sender, ValidationEventArgs e) {
    if(Convert.ToDouble(e.Value) <= 0)
        e.SetError("Negative values are not allowed. Please correct.", ErrorType.Critical);
}

The image below shows the result:

Validation_ErrorContent

See Also