You can create a regular expression cell that restricts the way data is entered in the cell to valid entries defined in a regular expression. The data is evaluated when exiting the cell. Invalid data is removed and the EditError event is raised.
You use the RegularExpressionCellType class to set the regular expression cell and its properties.
For a summary of regular expression syntax, refer to the Regular Expression Syntax topic in the Microsoft NET Framework Reference.
For an introduction to regular expressions, refer to the Introduction to Regular Expressions topic in the Microsoft .NET Framework Reference.
Using the Properties Window
- At design time, in the Properties window, select the Spread component.
- Select the Sheets property.
- Click the button to display the SheetView Collection Editor.
- In the Members list, select the sheet in which the cells appear.
- In the property list, select the Cells property and then click the button to display the Cell, Column, and Row Editor.
- Select the cells for which you want to set the cell type.
- In the property list, select the CellType property and choose the RegularExpression cell type.
- Expand the list of properties under the CellType property. Select and set these specific properties as needed.
- Click OK to close the Cell, Column, and Row Editor.
- Click OK to close the SheetView Collection Editor.
Using Code
- Define the regular expression cell by creating an instance of the RegularExpressionCellType class.
- Create a regular expression. Create a message to display to the user when expression is not valid.
- Assign the regular expression cell type to a cell or range of cells by setting the CellType property for a cell, column, row, or style to the RegularExpressionCellType object.
Example
C# | Copy Code |
---|---|
FarPoint.Win.Spread.CellType.RegularExpressionCellType regexcell = new FarPoint.Win.Spread.CellType.RegularExpressionCellType() regexcell.RegularExpression = "[0-9]{3}-[0-9]{2}-[0-9]{4}"; fpSpread1.ActiveSheet.Cells[0, 0].CellType = regexcell; |
VB | Copy Code |
---|---|
Dim regexcell As New FarPoint.Win.Spread.CellType.RegularExpressionCellType() regexcell.RegularExpression = "[0-9]{3}-[0-9]{2}-[0-9]{4}" FpSpread1.ActiveSheet.Cells(0, 0).CellType = regexcell |
Using the Spread Designer
- Select the cell or cells in the work area.
- In the property list, in the Misc category, select CellType. From the drop-down list, choose the RegularExpression cell type. Now expand the CellType property and various properties are available that are specific to this cell type. Select and set those properties as needed.
Or right-click on the cell or cells and select Cell Type. From the list, select RegularExpression. In the CellType editor, set the properties you need. Click Apply.
- From the File menu choose Apply and Exit to apply your changes to the component and exit Spread Designer.