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 Include List Validator
In This Topic
    Using the Include List Validator
    In This Topic

    You can create a validator that has a list of valid values.

    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 IncludeListValidator 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.

    Include List Validator

    Using Code

    The following example displays an invalid backcolor if you type an item from the list.

    CS
    Copy Code
    //Type an item in cell 1,1 that is not in the list to see the error notification
    FarPoint.Win.Spread.CellStyleNotify cnotify = new FarPoint.Win.Spread.CellStyleNotify();
    cnotify.InvalidCellStyle.BackColor = Color.Yellow;
    FarPoint.Win.Spread.IncludeListValidator ilist = new FarPoint.Win.Spread.IncludeListValidator();
    ilist.Candidates = new string[] { "Bird", "Deer", "Squirrel", "Lizard" };          
    ilist.Actions.Add(cnotify);
    fpSpread1.Sheets[0].AddValidators(new FarPoint.Win.Spread.Model.CellRange(1, 1, 1, 1), ilist);
    
    VB
    Copy Code
    'Type an item in cell 1,1 that is not in the list to see the error notification
    Dim cnotify As New FarPoint.Win.Spread.CellStyleNotify()
    cnotify.InvalidCellStyle.BackColor = Color.Yellow
    Dim IList As New FarPoint.Win.Spread.IncludeListValidator()
    IList.Candidates = New String() {"Bird", "Deer", "Squirrel", "Lizard"}
    IList.Actions.Add(cnotify)
    fpSpread1.Sheets(0).AddValidators(New FarPoint.Win.Spread.Model.CellRange(1, 1, 1, 1), IList)
    
    See Also