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 a Required Type Validator
In This Topic
    Using a Required Type Validator
    In This Topic

    You can create a validator that requires a valid type. The required type validator supports DateTime, TimeSpan, and Decimal (Numeric).

    A validation error occurs if the value is not valid. You can also create an action, such as adding a backcolor to the cell, that lets the user know the value is invalid.

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

    The following image displays an invalid backcolor in the cell.

    Required Type Validator

    Using Code

    The following example displays the invalid color if the value is not decimal or null.

    Copy Code
    //Type a text string in cell 1,1 to see the error notification
    FarPoint.Win.Spread.CellStyleNotify cnotify = new FarPoint.Win.Spread.CellStyleNotify();
    cnotify.InvalidCellStyle.BackColor = Color.Aqua;
    FarPoint.Win.Spread.RequiredTypeValidator requiredt = new FarPoint.Win.Spread.RequiredTypeValidator();
    requiredt.RequiredType = typeof(decimal);
    requiredt.NullIsValid = true;
    fpSpread1.Sheets[0].AddValidators(new FarPoint.Win.Spread.Model.CellRange(1, 1, 1, 1), requiredt);
    fpSpread1.Sheets[0].Cells[1, 1].Value = 5;
    Copy Code
    'Type a text string in cell 1,1 to see the error notification
    Dim cnotify As New FarPoint.Win.Spread.CellStyleNotify()
    cnotify.InvalidCellStyle.BackColor = Color.Aqua
    Dim requiredt As New FarPoint.Win.Spread.RequiredTypeValidator()
    requiredt.RequiredType = GetType(Decimal)
    requiredt.NullIsValid = True
    fpSpread1.Sheets(0).AddValidators(New FarPoint.Win.Spread.Model.CellRange(1, 1, 1, 1), requiredt)
    fpSpread1.Sheets(0).Cells(1, 1).Value = 5
    See Also