Skip to main content

DXErrorProvider.SetError(Control, String) Method

Sets the default 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.v24.1.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

public void SetError(
    Control control,
    string errorText
)

Parameters

Name Type Description
control Control

A control where an error occurred.

errorText String

The error text.

Remarks

Use the SetError method to set a Default-type error 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 a ErrorType.Default 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