officefileapi-devexpress-dot-spreadsheet-dot-datavalidationcollection-dot-validate-x28-devexpress-dot-spreadsheet-dot-cell-devexpress-dot-spreadsheet-dot-cellvalue-x29.md
Validates the specified value before assigning it to the specified cell.
Namespace : DevExpress.Spreadsheet
Assembly : DevExpress.Spreadsheet.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
bool Validate(
Cell cell,
CellValue newValue
)
Function Validate(
cell As Cell,
newValue As CellValue
) As Boolean
| 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.
|
| Type | Description |
|---|---|
| Boolean |
true , if the specified value meets the data validation criteria applied to the specified cell; otherwise, false.
|
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"]);
}
workbook.LoadDocument("Documents\DataValidation.xlsx")
Dim worksheet As 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:
Dim isValid As Boolean = worksheet.DataValidations.Validate(worksheet.Cells("D4"), worksheet.Cells("J4").Value)
If isValid Then
worksheet("D4").CopyFrom(worksheet("J4"))
End If
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.
//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"]); }
// Check whether the cell value meets a validation criteria.
bool isValid = worksheet.DataValidations.Validate(worksheet.Cells["D4"], worksheet.Cells["J4"].Value);
if (isValid) { worksheet["D4"].CopyFrom(worksheet["J4"]); }
'Check whether the cell value meets the validation criteria:
Dim isValid As Boolean = worksheet.DataValidations.Validate(worksheet.Cells("D4"), worksheet.Cells(CStr(("J4"))).Value)
If isValid Then
' Check whether the cell value meets a validation criteria.
Dim isValid As Boolean = worksheet.DataValidations.Validate(worksheet.Cells("D4"), worksheet.Cells("J4").Value)
If isValid Then
See Also
DataValidationCollection Interface