BaseEdit.ErrorText Property
Gets or sets the tooltip displayed when the mouse pointer hovers over the error icon.
Namespace: DevExpress.XtraEditors
Assembly: DevExpress.XtraEditors.v24.2.dll
Declaration
Property Value
Type | Description |
---|---|
String | A string value that specifies the tooltip displayed when the mouse pointer hovers over 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 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.
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.
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ErrorText property.
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.