Add Cell Data Validations
Contents
[
Hide
]
Aspose.Cells.GridWeb allows you to add Data Validation using the GridWorksheet.Validations.Add() method. Using this method, you have to specify the Cell Range. But if you want to create a Data Validation in a single GridCell then you can do it directly using GridCell.CreateValidation() method. Similarly, you can remove Data Validation from a GridCell using the GridCell.RemoveValidation() method.
Create Data Validation in a GridCell of GridWeb
The following sample code creates a Data Validation in a cell B3. If you enter any value which is not between 20 and 40, the cell B3 will show Validation Error in the form of Red XXXX as shown in this screenshot.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Access first worksheet | |
GridWorksheet sheet = GridWeb1.WorkSheets[0]; | |
// Access cell B3 | |
GridCell cell = sheet.Cells["B3"]; | |
// Add validation inside the gridcell | |
// Any value which is not between 20 and 40 will cause error in a gridcell | |
GridValidation val = cell.CreateValidation(GridValidationType.WholeNumber, true); | |
val.Formula1 = "=20"; | |
val.Formula2 = "=40"; | |
val.Operator = GridOperatorType.Between; | |
val.ShowError = true; | |
val.ShowInput = true; |