Skip to main content

DXErrorProvider.SetError(Control, String, ErrorType) Method

Sets an error icon next to a control. When a user hovers over this icon, a tooltip with an error message appears on-screen.

Namespace: DevExpress.XtraEditors.DXErrorProvider

Assembly: DevExpress.XtraEditors.v23.2.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

public void SetError(
    Control control,
    string errorText,
    ErrorType errorType
)

Parameters

Name Type Description
control Control

A control in which an error occurred.

errorText String

The error text.

errorType ErrorType

An ErrorType value that represents the error type, and the type of error icon that will be displayed.

Remarks

Use the SetError method to set an error with a specific type for a control. Note that this method only allows you to set errors for BaseEdit control descendants. For other controls, the method does nothing.

An error appears as an error icon next to the editor where it occurred. When users hover over the icon, a tooltip displays the specified error text.

An error that happened in an editor does not automatically clear itself on the editor’s value validation (when users leave the editor). To clear an error, call the SetError method with the errorText parameter set to an empty string.

The code sample below illustrates how to add an error message in case of validation failure.

DXErrorProvider errorProvider = new DXErrorProvider();

priceEdit.Validating += PriceEdit_Validating;

private void PriceEdit_Validating(object sender, CancelEventArgs e)
{
    var edit = sender as TextEdit;
    decimal r = 0.0M;
    if (!decimal.TryParse(edit.EditValue.ToString(), out r))
    {
        errorProvider.SetError(edit, "Invalid price", ErrorType.Critical);
        e.Cancel = true;
    }
}
See Also