GrapeCity MultiRow Windows Forms Documentation
RegularExpressionValidator

You can use RegularExpressionValidator and validate if a cell's value matches the specified regular expression. For further details about Regular Expressions, refer to WebSite .NET Framework Regular Expressions.

Using Designer

Complete the following steps to validate using a regular expression. The example displays a validation error if a string other than an e-mail address has been entered in the textBoxCell.

  1. Select a cell for which to validate the value (for example, textBoxCell1).
  2. From the Properties window, select the Validators property and click the ... button.
  3. From the displayed CellValidator collection editor, select RegularExpressionValidator from the top-left combo box and click the Add button.
  4. From the Members list, confirm that RegularExpressionValidator has been selected.
  5. Select the Expression property from the property grid and click the ... button for pre-defined expressions.
  6. Select the expression for e-mail address \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* and click the OK button.
  7. Select the Actions property from the property grid and click the ... button.
  8. Add LineNotify in the displayed CellValidateAction collection editor.
  9. Click the OK button and close the CellValidateAction collection editor.
  10. Click the OK button and close the CellValidator collection editor.
  11. Change the document window tab of the designer to Runtime.
  12. Enter john.willsonxyz.com, move the focus from the cell, and verify the occurrence of a validation error.
  13. Now add the @ sign to correct the e-mail address and move to another cell. Confirm that no error occurs.

Using Code

The following code displays a validation error if a string other than an e-mail address has been entered in the cell.

[VB]

Imports GrapeCity.Win.MultiRow

Dim textBoxCell1 As New TextBoxCell()
Dim regularExpressionValidator1 As New RegularExpressionValidator()
regularExpressionValidator1.Expression = "\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
regularExpressionValidator1.Actions.Add(New LineNotify())
textBoxCell1.Validators.Add(regularExpressionValidator1)

Dim cells As Cell() = {textBoxCell1}
GcMultiRow1.Template = Template.CreateGridTemplate(cells)
GcMultiRow1.RowCount = 10

[CS]

using GrapeCity.Win.MultiRow;

TextBoxCell textBoxCell1 = new TextBoxCell();
RegularExpressionValidator regularExpressionValidator1 = new RegularExpressionValidator();
regularExpressionValidator1.Expression = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
regularExpressionValidator1.Actions.Add(new LineNotify());
textBoxCell1.Validators.Add(regularExpressionValidator1);

Cell[] cells = { textBoxCell1 };
gcMultiRow1.Template = Template.CreateGridTemplate(cells);
gcMultiRow1.RowCount = 10;
See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options