officefileapi-devexpress-dot-spreadsheet-dot-datavalidationcollection-dot-add-x28-devexpress-dot-spreadsheet-dot-cellrange-devexpress-dot-spreadsheet-dot-datavalidationtype-devexpress-dot-spreadsheet-dot-valueobject-x29.md
Creates a new data validation entry and adds it to the document’s collection.
Namespace : DevExpress.Spreadsheet
Assembly : DevExpress.Spreadsheet.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
DataValidation Add(
CellRange range,
DataValidationType validationType,
ValueObject criteria
)
Function Add(
range As CellRange,
validationType As DataValidationType,
criteria As ValueObject
) As DataValidation
| Name | Type | Description |
|---|---|---|
| range | CellRange |
A CellRange object that is the worksheet range to which the data validation rule is applied.
| | validationType | DataValidationType |
A DataValidationType enumeration member that specifies the validation type.
| | criteria | ValueObject |
A ValueObject that is the value used in the criterion.
|
| Type | Description |
|---|---|
| DataValidation |
A DataValidation object that specifies a validation rule for a worksheet range.
|
This method overload is used for validation types DataValidationType.Custom and DataValidationType.List.
For the DataValidationType.Custom type, the criteria is a string which can be recognized as a worksheet formula. Therefore, it must begin with an equal sign and evaluate to either true or false.
Note
An individual worksheet cell can have only one data validation rule associated with it. If subsequent Add method calls affect the same cell, only the data validation rule created in the last call is applied.
The following code snippets (auto-collected from DevExpress Examples) contain references to the Add(CellRange, DataValidationType, ValueObject) method.
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.
// Restrict data entry using criteria calculated by a worksheet formula.
worksheet.DataValidations.Add(worksheet["B4:B11"], DataValidationType.Custom, "=AND(ISNUMBER(B4),LEN(B4)=5)");
// Restrict data entry using criteria calculated by a worksheet formula.
worksheet.DataValidations.Add(worksheet["B4:B11"], DataValidationType.Custom, "=AND(ISNUMBER(B4),LEN(B4)=5)");
// Restrict data entry based on a formula.
worksheet.DataValidations.Add(worksheet["B4:B11"], DataValidationType.Custom, "=AND(ISNUMBER(B4),LEN(B4)=5)");
' Restrict data entry using criteria calculated by a worksheet formula.
worksheet.DataValidations.Add(worksheet("B4:B11"), DevExpress.Spreadsheet.DataValidationType.Custom, "=AND(ISNUMBER(B4),LEN(B4)=5)")
' Restrict data entry to 3 symbols.
' Restrict data entry based on a formula.
worksheet.DataValidations.Add(worksheet("B4:B11"), DataValidationType.Custom, "=AND(ISNUMBER(B4),LEN(B4)=5)")
See Also
DataValidationCollection Interface