Skip to main content
Row

DataValidationCollection.GetDataValidations(DataValidationType, DataValidationOperator, ValueObject, ValueObject) Method

Obtains data validation entries with the specified properties.

Namespace: DevExpress.Spreadsheet

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

NuGet Package: DevExpress.Spreadsheet.Core

Declaration

IList<DataValidation> GetDataValidations(
    DataValidationType validationType,
    DataValidationOperator validationOperator,
    ValueObject criteria,
    ValueObject criteria2
)

Parameters

Name Type Description
validationType DataValidationType

A DataValidationType enumeration member that specifies the validation type.

validationOperator DataValidationOperator

A DataValidationOperator enumeration member that specifies the operator used in a criteria expression.

criteria ValueObject

A ValueObject that is the value used in the criterion.

criteria2 ValueObject

A ValueObject that is the value used in the criterion.

Returns

Type Description
IList<DataValidation>

A IList<T><DataValidation,> collection of data validation entries.

Example

View Example

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

// Add data validations.
worksheet.DataValidations.Add(worksheet["D4:D11"], DataValidationType.TextLength, DataValidationOperator.Equal, 3);
worksheet.DataValidations.Add(worksheet["E4:E11"], DataValidationType.List, ValueObject.FromRange(worksheet["H4:H9"].GetRangeWithAbsoluteReference()));

// Get data validation entry associated with a particular cell.
worksheet.DataValidations.GetDataValidation(worksheet.Cells["E4"]).Criteria = ValueObject.FromRange(worksheet["H4:H5"]);

// Get data validation entries for the specified range.
var myValidation = worksheet.DataValidations.GetDataValidations(worksheet["D4:E11"])
    .Where(d => d.ValidationType == DataValidationType.TextLength).SingleOrDefault();
if (myValidation != null) myValidation.Criteria = 4;

// Get data validation entries that meet certain criteria.
foreach (var d in worksheet.DataValidations.GetDataValidations(DataValidationType.TextLength, DataValidationOperator.Equal, 4, ValueObject.Empty))
{
    // Change criteria operator.
    // Range D4:D11 should contain text with more than 4 characters.
    d.Operator = DataValidationOperator.GreaterThan;
}              

// 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]);
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the GetDataValidations(DataValidationType, DataValidationOperator, ValueObject, 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.

See Also