Back to Devexpress

ValidationEventArgs.SetError(Object) Method

wpf-devexpress-dot-xpf-dot-editors-dot-validationeventargs-dot-seterror-x28-system-dot-object-x29.md

latest3.5 KB
Original Source

ValidationEventArgs.SetError(Object) Method

Marks the processed input value as invalid and displays an error within the editor.

Namespace : DevExpress.Xpf.Editors

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

NuGet Package : DevExpress.Wpf.Core

Declaration

csharp
public void SetError(
    object errorContent
)
vb
Public Sub SetError(
    errorContent As Object
)

Parameters

NameTypeDescription
errorContentObject

An object that specifies the error content.

|

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.

csharp
private void textEdit_Validate(object sender, ValidationEventArgs e) {
    if(Convert.ToDouble(e.Value) < 0)
        e.SetError("Negative values are not allowed.");
}
vb
Private Sub textEdit_Validate(ByVal sender As Object, ByVal e As ValidationEventArgs)
    If Convert.ToDouble(e.Value) < 0 Then
        e.SetError("Negative values are not allowed.")
    End If
End Sub

The image below shows the result:

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SetError(Object) method.

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.

wpf-data-grid-validate-data-rows/CS/ValidateRow_CodeBehind/MainWindow.xaml.cs#L59

csharp
if(task.StartDate > task.EndDate)
    e.SetError("Start Date must be less than End Date");
if(string.IsNullOrEmpty(task.TaskName))

wpf-data-grid-validate-data-rows/VB/ValidateRow_CodeBehind/MainWindow.xaml.vb#L50

vb
Dim task = CType(e.Row, Task)
If task.StartDate > task.EndDate Then e.SetError("Start Date must be less than End Date")
If String.IsNullOrEmpty(task.TaskName) Then e.SetError("Enter a task name")

See Also

ValidationEventArgs Class

ValidationEventArgs Members

DevExpress.Xpf.Editors Namespace