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 Cell Comparison Validator
In This Topic
    Using a Cell Comparison Validator
    In This Topic

    You can create a validator that compares the cell value to another cell's value. You can compare DateTime, TimeSpan, or Decimal type (Numeric) values.

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

    Use the CompareCellValidator class to create the validation conditions. Specify a notification type such as LineNotify. Then use the AddValidators method to add the validator to a cell range.

    The following image displays a red underline for an invalid value.

    Spreadsheet cell displaying a validation error

    Using Code

    The following example adds a red underline if you type a value less than or equal to 10 in cell 1,1.

    CS
    Copy Code
    //Type a value equal to or less than 10 to see the red line
                    FarPoint.Win.Spread.LineNotify linen = new FarPoint.Win.Spread.LineNotify();
                    linen.LineColor = Color.Red;
                    linen.DoActionReason = FarPoint.Win.Spread.ValidateReasons.EndEdit;
                    FarPoint.Win.Spread.CompareCellValidator compare = new FarPoint.Win.Spread.CompareCellValidator();
                    compare.ComparedOperator = FarPoint.Win.Spread.ValidateComparisonOperator.GreaterThan;
                    compare.Row = 0;
                    compare.Column = 0;
                    compare.Actions.Add(linen);
                    fpSpread1.Sheets[0].AddValidators(new FarPoint.Win.Spread.Model.CellRange(1, 1, 1, 1), compare);
                    fpSpread1.Sheets[0].Cells[0, 0].Value = 10;
    
    VB
    Copy Code
    'Type a value equal to Or less than 10 to see the red line
                    Dim linen As New FarPoint.Win.Spread.LineNotify()
                    linen.LineColor = Color.Red
                    linen.DoActionReason = FarPoint.Win.Spread.ValidateReasons.EndEdit
                    Dim compare As New FarPoint.Win.Spread.CompareCellValidator()
                    compare.ComparedOperator = FarPoint.Win.Spread.ValidateComparisonOperator.GreaterThan
                    compare.Row = 0
                    compare.Column = 0
                    compare.Actions.Add(linen)
                    fpSpread1.Sheets(0).AddValidators(New FarPoint.Win.Spread.Model.CellRange(1, 1, 1, 1), compare)
                    fpSpread1.Sheets(0).Cells(0, 0).Value = 10
    
    See Also