Spread Windows Forms 8.0 Product Documentation
Setting a Regular Expression Cell

You can create a regular expression cell that restricts the data 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

  1. At design time, in the Properties window, select the Spread component.
  2. Select the Sheets property.
  3. Click the button to display the SheetView Collection Editor.
  4. In the Members list, select the sheet in which the cells appear.
  5. In the property list, select the Cells property and then click the button to display the Cell, Column, and Row Editor.
  6. Select the cells for which you want to set the cell type.
  7. In the property list, select the CellType property and choose the RegularExpression cell type.
  8. Expand the list of properties under the CellType property. Select and set these specific properties as needed.
  9. Click OK to close the Cell, Column, and Row Editor.
  10. Click OK to close the SheetView Collection Editor.

Using Code

  1. Define the regular expression cell by creating an instance of the RegularExpressionCellType class.
  2. Create a regular expression.
  3. Create a message to display to the user when the expression is not valid.
  4. 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

This example creates a regular expression cell.

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

  1. Select the cell or cells in the work area.
  2. 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.

  3. From the File menu choose Apply and Exit to apply your changes to the component and exit Spread Designer.
See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options | Documentation Feedback