Back to Devexpress

DataValidation.ErrorStyle Property

officefileapi-devexpress-dot-spreadsheet-dot-datavalidation-4767b021.md

latest7.1 KB
Original Source

DataValidation.ErrorStyle Property

Gets or sets the style of the alert dialog window used for data validation.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
DataValidationErrorStyle ErrorStyle { get; set; }
vb
Property ErrorStyle As DataValidationErrorStyle

Property Value

TypeDescription
DataValidationErrorStyle

A DataValidationErrorStyle enumeration value that specifies the style of error alert.

|

Available values:

NameDescription
Stop

The dialog displays the Stop icon; the only options are Retry or Cancel; end-users are not allowed to enter invalid data in the cell.

| | Warning |

The dialog displays the Warning icon; the end-user can decide whether to allow entry of the invalid data, to retry, or to remove the invalid entry.

| | Information |

The dialog displays the Information icon; the end-user can click OK to accept the invalid value or Cancel to reject it.

|

Example

The following code snippet adds a new data validation rule and customizes the error dialog invoked when validation fails for the user’s input.

The customized dialog is shown in the image below.

View Example

csharp
workbook.LoadDocument("Documents\\DataValidation.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

// Restrict data entry to a 5-digit number.
DataValidation validation = worksheet.DataValidations.Add(worksheet["B4:B11"], DataValidationType.Custom, "=AND(ISNUMBER(B4),LEN(B4)=5)");

// Show error message.
validation.ErrorTitle = "Wrong Employee Id";
validation.ErrorMessage = "The value you entered is not valid. Use 5-digit number for the employee ID.";
validation.ErrorStyle = DataValidationErrorStyle.Information;
validation.ShowErrorMessage = true;

// Highlight data validation ranges.
int[] MyColorScheme = new int[] { 0xFFC4C4, 0xFFD9D9, 0xFFF6F6, 0xFFECEC, 0xE9D3D3 };
for (int i = 0; i < worksheet.DataValidations.Count; i++)
{
    worksheet.DataValidations[i].Range.FillColor = Color.FromArgb(MyColorScheme[i]);
}
vb
workbook.LoadDocument("Documents\DataValidation.xlsx")
Dim worksheet As Worksheet = workbook.Worksheets(0)

' Restrict data entry to a 5-digit number.
Dim validation As DataValidation = worksheet.DataValidations.Add(worksheet("B4:B11"), DataValidationType.Custom, "=AND(ISNUMBER(B4),LEN(B4)=5)")

' Show error message.
validation.ErrorTitle = "Wrong Employee Id"
validation.ErrorMessage = "The value you entered is not valid. Use 5-digit number for the employee ID."
validation.ErrorStyle = DataValidationErrorStyle.Information
validation.ShowErrorMessage = True

' Highlight data validation ranges.
Dim MyColorScheme() As Integer = { &HFFC4C4, &HFFD9D9, &HFFF6F6, &HFFECEC, &HE9D3D3 }
For i As Integer = 0 To worksheet.DataValidations.Count - 1
    worksheet.DataValidations(i).Range.FillColor = Color.FromArgb(MyColorScheme(i))
Next i

The following code snippets (auto-collected from DevExpress Examples) contain references to the ErrorStyle 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-spreadsheetcontrol-api-part-3/CS/SpreadsheetControl_API_Part03/CodeExamples/DataValidationActions.cs#L124

csharp
validation.ErrorMessage = "The value you entered is not valid. Use 5-digit number for the employee ID.";
validation.ErrorStyle = DataValidationErrorStyle.Information;
validation.ShowErrorMessage = true;

wpf-spreadsheetcontrol-api-part-2/CS/SpreadsheetControl_WPF_API_Part02/SpreadsheetActions/DataValidationActions.cs#L136

csharp
validation.ErrorMessage = "The value you entered is not valid. Use 5-digit number for the employee ID.";
validation.ErrorStyle = DataValidationErrorStyle.Information;
validation.ShowErrorMessage = true;

spreadsheet-document-api-examples-part2/CS/SpreadsheetDocServerAPIPart2/CodeExamples/DataValidationActions.cs#L157

csharp
validation.ErrorMessage = "The value you entered is not valid. Use 5-digit number for the employee ID.";
validation.ErrorStyle = DataValidationErrorStyle.Information;
validation.ShowErrorMessage = true;

winforms-spreadsheetcontrol-api-part-3/VB/SpreadsheetControl_API_Part03/CodeExamples/DataValidationActions.vb#L103

vb
validation.ErrorMessage = "The value you entered is not valid. Use 5-digit number for the employee ID."
validation.ErrorStyle = DevExpress.Spreadsheet.DataValidationErrorStyle.Information
validation.ShowErrorMessage = True

spreadsheet-document-api-examples-part2/VB/SpreadsheetDocServerAPIPart2/CodeExamples/DataValidationActions.vb#L151

vb
validation.ErrorMessage = "The value you entered is not valid. Use 5-digit number for the employee ID."
validation.ErrorStyle = DataValidationErrorStyle.Information
validation.ShowErrorMessage = True

See Also

DataValidation Interface

DataValidation Members

DevExpress.Spreadsheet Namespace