Back to Devexpress

BaseEdit.ErrorText Property

windowsforms-devexpress-dot-xtraeditors-dot-baseedit-21f135ec.md

latest7.9 KB
Original Source

BaseEdit.ErrorText Property

Gets or sets the tooltip displayed when the mouse pointer hovers over the error icon.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[Browsable(false)]
public string ErrorText { get; set; }
vb
<Browsable(False)>
Public Property ErrorText As String

Property Value

TypeDescription
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 an editor to indicate that the editor value is not valid. The default icon is displayed to the left of the editor.

Customize the Default Error Icon

Use the static (Shared in VB) DefaultErrorImageOptions property to access options that allow you to customize the error icon for all editors:

Image/SvgImageSpecifies a custom image used as an error icon.AlignmentSpecifies image alignment relatively to the editor.

Note

Specify these properties before editor initialization (in the Main method). Editors do not react to subsequent changes.

csharp
static void Main() {
  BaseEdit.DefaultErrorImageOptions.SvgImage = Properties.Resources.errorIcon;
  BaseEdit.DefaultErrorImageOptions.Alignment = ErrorIconAlignment.BottomRight;

  Application.EnableVisualStyles();
  Application.SetCompatibleTextRenderingDefault(false);
  Application.Run(new Form1());
}
vb
Shared Sub Main()
  BaseEdit.DefaultErrorImageOptions.SvgImage = My.Resources.errorIcon
  BaseEdit.DefaultErrorImageOptions.Alignment = ErrorIconAlignment.BottomRight

  Application.EnableVisualStyles()
  Application.SetCompatibleTextRenderingDefault(False)
  Application.Run(New Form1())
End Sub

Customize the Error Icon for an Individual Editor

Use an editor’s ErrorImageOptions property to access the following options:

Image/SvgImageSpecifies a custom image used as an error icon.AlignmentSpecifies image alignment relatively to the editor.

Individual editor settings have priority over DefaultErrorImageOptions settings.

csharp
public Form1() {
  InitializeComponent();
  textEdit1.ErrorImageOptions.SvgImage = svgImageCollection1["error"];
  textEdit1.ErrorImageOptions.Alignment = ErrorIconAlignment.TopLeft;
}
vb
Public Sub New()
  InitializeComponent()
  textEdit1.ErrorImageOptions.SvgImage = svgImageCollection1("error")
  textEdit1.ErrorImageOptions.Alignment = ErrorIconAlignment.TopLeft
End Sub

Customize Error Tooltip Text

Use the ErrorText property to specify error tooltip text for a standalone editor. If you use an editor in a data-aware control, use the parent control’s ValidatingEditor event to validate the editor value and display an error icon. Read the following help topic for more information: Manage user Input.


Tip

For information on how to validate editor values, read the following help topic: Validation.

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.

csharp
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;
    }
}
vb
Imports DevExpress.XtraEditors

Private Sub textEdit1_Validating(ByVal sender As Object, ByVal e As CancelEventArgs) _
    Handles textEdit1.Validating
    Dim textEdit As TextEdit = TryCast(sender, TextEdit)
    Dim editValue As String = TryCast(textEdit.EditValue, String)
    Dim regex As New Regex("^[a-zA-Z0-9]*$")
    If Not regex.IsMatch(editValue) Then
        textEdit.ErrorText = "The name should only contain alphanumeric characters"
        textEdit.ErrorImageOptions.Image = svgImageCollection1.GetImage(0, new Size(12, 12))
        e.Cancel = True
    End If
End Sub

Tip

You can also use the ErrorProvider component to validate editors.

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.

winforms-scheduler-localizer-translate-ui/CS/SchedulerLocalizerExample/OutlookAppointmentForm.cs#L348

csharp
return String.IsNullOrEmpty(this.edtEndTime.ErrorText) && String.IsNullOrEmpty(this.edtEndDate.ErrorText) && String.IsNullOrEmpty(this.edtStartDate.ErrorText) && String.IsNullOrEmpty(this.edtStartTime.ErrorText);
}

winforms-scheduler-localizer-translate-ui/VB/SchedulerLocalizationExample_VB/OutlookAppointmentForm.vb#L385

vb
Return [String].IsNullOrEmpty(Me.edtEndTime.ErrorText) AndAlso [String].IsNullOrEmpty(Me.edtEndDate.ErrorText) AndAlso [String].IsNullOrEmpty(Me.edtStartDate.ErrorText) AndAlso [String].IsNullOrEmpty(Me.edtStartTime.ErrorText)
End Function

See Also

Validating

DefaultErrorImageOptions

ErrorImageOptions

BaseEdit Class

BaseEdit Members

DevExpress.XtraEditors Namespace