Skip to main content

BaseEdit.ErrorIcon Property

Gets or sets an icon displayed when an error is associated with the editor.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v24.1.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public Image ErrorIcon { get; set; }

Property Value

Type Description
Image

A Image object that specifies the error icon.

Remarks

You can display an error icon next to the editor to indicate that the editor’s value is not valid. The default Default Error Icon icon is displayed to the left of the editor. Use the static (Shared in VB) DefaultErrorImageOptions property to access the following options that allow you to customize the default icon:

  • Image — a custom raster image used as an error icon. The icon’s size must be 12x12 pixels. This property is equivalent to the DefaultErrorIcon property.
  • Alignment — an alignment relative to the editor. This property is equivalent to the DefaultErrorIconAlignment property.

Update these properties before the editor is initialized. You can also use the ErrorImageOptions property to access the same options that allow you to customize the error icon for an individual editor:

  • Image — a custom raster image used as an error icon. This property is equivalent to the ErrorIcon property.
  • Alignment — an alignment relative to the editor. This property is equivalent to the ErrorIconAlignment property.

The icon is shown if an error message is assigned to the ErrorText property. The error message is displayed in a tooltip that appears when the mouse pointer hovers over the icon.

Error Icon

Tip

Use the ErrorText property to display an icon with a tooltip next to a stand-alone editor. If you use an editor in a data-aware control, use the control’s following events to validate an editor’s value and display an error icon: BaseView.ValidatingEditor, TreeList.ValidatingEditor, and VGridControlBase.ValidatingEditor.

If an editor value is invalid (the error icon and text are shown), users can press “Esc” to clear the ErrorText and revert the editor back to its OldEditValue. To disable this default behavior, handle the KeyPress event:

txtNewNote.KeyPress += TxtNewNote_KeyPress;

private void TxtNewNote_KeyPress(object sender, KeyPressEventArgs e) {
    MemoEdit edit = sender as MemoEdit;
    if (e.KeyChar == (char)Keys.Escape && !string.IsNullOrEmpty(edit.ErrorText))
        e.Handled = true;
}

Example

You can handle the Control.Validating or RepositoryItem.Validating event to validate the editor’s value. The code below uses the ErrorText property to inform a user how to correct the value.

using DevExpress.XtraEditors;

private void textEdit1_Validating(object sender, CancelEventArgs e) {
    TextEdit textEdit = sender as TextEdit;
    string editValue = textEdit.EditValue as string;
    Regex regex = new Regex("^[a-zA-Z0-9 ]*$");
    if (!regex.IsMatch(editValue)) {
        textEdit.ErrorText = "The name should only contain alphanumeric characters";
        textEdit.ErrorImageOptions.Image = svgImageCollection1.GetImage(0, new Size(12, 12));
        e.Cancel = true;
    }
}

Tip

You can also use the ErrorProvider component to validate editors.

See Also