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 Character Format Validator
In This Topic
    Using a Character Format Validator
    In This Topic

    You can create a validator that checks for specific characters.

    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 CharFormatValidator 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 for the cell.

    Spereadsheet cell displaying a blue backcolor for an invalid value

    Using Code

    The following example displays an invalid backcolor if you type characters other than the format string.

    Copy Code
    FarPoint.Win.Spread.CellStyleNotify cnotify = new FarPoint.Win.Spread.CellStyleNotify();
    cnotify.InvalidCellStyle.BackColor = Color.Aqua;
    FarPoint.Win.Spread.CharFormatValidator cFormatValidator1 = new FarPoint.Win.Spread.CharFormatValidator();
    cFormatValidator1.Format = "Aa";
    fpSpread1.Sheets[0].AddValidators(new FarPoint.Win.Spread.Model.CellRange(1, 1, 1, 1), cFormatValidator1);
    Copy Code
    Dim cnotify As New FarPoint.Win.Spread.CellStyleNotify()
    cnotify.InvalidCellStyle.BackColor = Color.Aqua
    Dim charFormatValidator1 As New FarPoint.Win.Spread.CharFormatValidator()
    charFormatValidator1.Format = "Aa"
    fpSpread1.Sheets(0).AddValidators(New FarPoint.Win.Spread.Model.CellRange(1, 1, 1, 1), charFormatValidator1)
    See Also