Spread Windows Forms 15.0
Spread Windows Forms 15.0 Product Documentation / Developer's Guide / Customizing Interaction in Cells / Using Validation / Using Validation in Cells / Using the Range Validator
In This Topic
    Using the Range Validator
    In This Topic

    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.

    Range Validator Example

    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