Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+
Row

DataValidationCollection.Validate(Cell, CellValue) Method

Validates the specified value before assigning it to the specified cell.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v19.1.Core.dll

Declaration

bool Validate(
    Cell cell,
    CellValue newValue
)

Parameters

Name Type Description
cell Cell

A Cell object that is a cell with the data validation applied.

newValue CellValue

A CellValue object that is a value to be validated.

Returns

Type Description
Boolean

true, if the specified value meets the data validation criteria applied to the specified cell; otherwise, false.

Remarks

Use the Validate method to check whether a value that should be assigned to the specified cell meets the data validation criteria applied to that cell.

If the newValue is empty, the Validate method’s result depends on the DataValidation.AllowBlank property of the data validation rule applied to the specified cell. If a cell does not have any data validation applied, the Validate method always returns true.

Use the other Validate method overload to check whether a particular cell in a worksheet contains valid data.

The DataValidationCollection.GetInvalidCells method allows you to obtain the collection of cells that do not match the data validation criteria in a worksheet.

The code sample below shows how to use the Validate method to check whether the cell value meets the validation criteria:

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

// Add data validations.
worksheet.DataValidations.Add(worksheet["D4:D11"], DataValidationType.TextLength, DataValidationOperator.Equal, 3);

//Check whether the cell value meets the validation criteria:
bool isValid = worksheet.DataValidations.Validate(worksheet.Cells["D4"], worksheet.Cells["J4"].Value);
if (isValid)
{
    worksheet["D4"].CopyFrom(worksheet["J4"]);
}
See Also