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

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.2.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