Spread Windows Forms 17
Spread Windows Forms 17.0 Product Documentation / Developer's Guide / Customizing Interaction in Cells / Using Validation / Using Validation in Cells / Using a Required Field Validator
In This Topic
    Using a Required Field Validator
    In This Topic

    You can use the required field validator to specify that the cell requires a value.

    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 RequiredFieldValidator 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 a cell with an invalid, empty value.

    Required Fill Validator

    Using Code

    The following example displays the invalid color if the value is deleted from the cell.

    CS
    Copy Code
    //Cell 1,1 requires a value
    FarPoint.Win.Spread.CellStyleNotify cnotify = new FarPoint.Win.Spread.CellStyleNotify();
    cnotify.InvalidCellStyle.BackColor = Color.Fuchsia;
    FarPoint.Win.Spread.RequiredFieldValidator requiredv = new FarPoint.Win.Spread.RequiredFieldValidator();
    requiredv.Actions.Add(cnotify);
    fpSpread1.Sheets[0].AddValidators(new FarPoint.Win.Spread.Model.CellRange(1, 1, 1, 1), requiredv);
    fpSpread1.Sheets[0].Cells[1, 1].Text = "Value";
    
    VB
    Copy Code
    'Cell 1,1 requires a value
    Dim cnotify As New FarPoint.Win.Spread.CellStyleNotify()
    cnotify.InvalidCellStyle.BackColor = Color.Fuchsia
    Dim requiredv As New FarPoint.Win.Spread.RequiredFieldValidator()
    requiredv.Actions.Add(cnotify)
    fpSpread1.Sheets(0).AddValidators(New FarPoint.Win.Spread.Model.CellRange(1, 1, 1, 1), requiredv)
    fpSpread1.Sheets(0).Cells(1, 1).Text = "Value"
    
    See Also