Spread Windows Forms 12.0 Product Documentation
Using a String Comparison Validator
Spread Windows Forms 12.0 Product Documentation > Developer's Guide > Customizing Interaction in Cells > Using Validation in Cells > Using a String Comparison Validator

You can create a validator that compares string values.

A validation error occurs if the value does not match the specified conditions. You can also create an action, such as displaying an icon in the cell, that lets the user know the value is invalid.

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

The following image displays an error icon with a text tip.

Using Code

The following example displays an icon if you type a string that does not contain "Test".

Copy Code
//Type a value in cell 1,1
FarPoint.Win.Spread.IconNotify iconn = new FarPoint.Win.Spread.IconNotify();
iconn.Icon = new System.Drawing.Icon("C:\\Program Files (x86)\\GrapeCity\\spread.ico");
iconn.IconAlignment = ContentAlignment.MiddleCenter;
iconn.IconTip = "Must contain Test";
FarPoint.Win.Spread.CompareStringValidator svalid = new FarPoint.Win.Spread.CompareStringValidator();
svalid.ComparedOperator = FarPoint.Win.Spread.CompareStringValidatorOperator.Contains;
svalid.ComparedString = "Test";
fpSpread1.Sheets[0].AddValidators(new FarPoint.Win.Spread.Model.CellRange(1, 1, 1, 1), svalid);
fpSpread1.Sheets[0].Columns[1].Width = 140;
fpSpread1.Sheets[0].Rows[1].Height = 50;
Copy Code
'Type a value in cell 1,1
Dim iconn As New FarPoint.Win.Spread.IconNotify()
iconn.Icon = New System.Drawing.Icon("C:\Program Files (x86)\GrapeCity\spread.ico")
iconn.IconAlignment = ContentAlignment.MiddleCenter
iconn.IconTip = "Must contain Test"
Dim svalid As New FarPoint.Win.Spread.CompareStringValidator()
svalid.ComparedOperator = FarPoint.Win.Spread.CompareStringValidatorOperator.Contains
svalid.ComparedString = "Test"
fpSpread1.Sheets(0).AddValidators(New FarPoint.Win.Spread.Model.CellRange(1, 1, 1, 1), svalid)
fpSpread1.Sheets(0).Columns(1).Width = 140
fpSpread1.Sheets(0).Rows(1).Height = 50