Skip to main content
Row

DataValidationCollection.Validate(Cell, CellValue) Method

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

Namespace: DevExpress.Spreadsheet

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

NuGet Package: DevExpress.Spreadsheet.Core

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

The following code snippets (auto-collected from DevExpress Examples) contain references to the Validate(Cell, CellValue) 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