Skip to main content
Row

DataValidationCollection.GetDataValidations(CellRange) Method

Obtains data validation entries for cells in the specified range.

Namespace: DevExpress.Spreadsheet

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

NuGet Package: DevExpress.Spreadsheet.Core

Declaration

IList<DataValidation> GetDataValidations(
    CellRange range
)

Parameters

Name Type Description
range CellRange

A CellRange containing cells for which data validation entries are obtained.

Returns

Type Description
IList<DataValidation>

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

Remarks

Each cell can have only one data validation entry associated with it.

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