GrapeCity MultiRow Windows Forms Documentation
TextLengthValidator

You can use the TextLengthValidator class to validate whether the height of a cell's value falls within the specified range. A validation error occurs if the height of the value does not fall within the specified range.

Using the Designer

Use the following instructions to validate the height of a cell's value.

  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 TextLengthValidator from the left-top combo box and click the Add button.
  4. From the Members list, confirm that TextLengthValidator has been selected.
  5. Select the Encoding property from the property grid and select Unicode.
  6. Select the LengthUnit property from the property grid and select Byte.
  7. Select the MaximumLength property from the property grid and type 5.
  8. Select the Actions property from the property grid and click the ... button.
  9. Add LineNotify in the displayed CellValidateAction collection editor.
  10. Click the OK button and close the CellValidateAction collection editor.
  11. Click the OK button and close the CellValidator collection editor.
  12. Change the document window tab of the designer to Runtime.
  13. Enter AAAAAA and confirm that the validation error occurs when you move to another cell.
  14. Delete AAAAAA, enter AAA and confirm that the validation error does not occur when you move to another cell.

Using Code

The following code illustrates the validation error when a string of more than 5 bytes is entered in the cell.

[VB]

Imports GrapeCity.Win.MultiRow

Dim textBoxCell1 As New TextBoxCell()
Dim textLengthValidator1 As New TextLengthValidator()
textLengthValidator1.Encoding = System.Text.Encoding.GetEncoding("Unicode")
textLengthValidator1.LengthUnit = LengthUnit.Byte
textLengthValidator1.MaximumLength = 5
textLengthValidator1.Actions.Add(New LineNotify())
textBoxCell1.Validators.Add(textLengthValidator1)

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

[CS]

using GrapeCity.Win.MultiRow;

TextBoxCell textBoxCell1 = new TextBoxCell();
TextLengthValidator textLengthValidator1 = new TextLengthValidator();
textLengthValidator1.Encoding = System.Text.Encoding.GetEncoding("Unicode");
textLengthValidator1.LengthUnit = LengthUnit.Byte;
textLengthValidator1.MaximumLength = 5;
textLengthValidator1.Actions.Add(new LineNotify());
textBoxCell1.Validators.Add(textLengthValidator1);

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

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options