Spread Windows Forms 11.0 Product Documentation
Using the Range Validator
Spread Windows Forms 11.0 Product Documentation > Developer's Guide > Customizing Interaction in Cells > Using Validation in Cells > Using the Range Validator

You can use the range validator to check to see if a value is within a specified range. A validation error occurs if the value is not within the specified range. You can also create an action, such as changing the cell backcolor, that lets the user know the value is invalid.

Use the RangeValidator class to create the validation conditions. Specify a notification type such as CellStyleNotify. Then use the AddValidators method to add the validator to a cell range.

The following image uses the CellStyleNotify class to change the cell backcolor when an invalid value is typed.

Using Code

The following example sets a minimum and maximum value for the cell. A different backcolor is shown if you type an invalid value in the cell.

CS
Copy Code
FarPoint.Win.Spread.CellStyleNotify stylenotify = new FarPoint.Win.Spread.CellStyleNotify();
stylenotify.InvalidCellStyle.BackColor = Color.Aquamarine;
FarPoint.Win.Spread.RangeValidator rvalid = new FarPoint.Win.Spread.RangeValidator();
rvalid.MaxValue = 10;
rvalid.MinValue = 0;
rvalid.Actions.Add(stylenotify);
fpSpread1.Sheets[0].AddValidators(new FarPoint.Win.Spread.Model.CellRange(1, 1, 1, 1), rvalid);
VB
Copy Code
Dim stylenotify As New FarPoint.Win.Spread.CellStyleNotify()
stylenotify.InvalidCellStyle.BackColor = Color.Aquamarine
Dim rvalid As New FarPoint.Win.Spread.RangeValidator()
rvalid.MaxValue = 10
rvalid.MinValue = 0
rvalid.Actions.Add(stylenotify)
fpSpread1.Sheets(0).AddValidators(New FarPoint.Win.Spread.Model.CellRange(1, 1, 1, 1), rvalid)
See Also