GrapeCity MultiRow Windows Forms Documentation
RequiredTypeValidator

You can use RequiredTypeValidator and validate if the value entered in a cell matches the specified type. RequiredTypeValidator supports only DateTime, TimeSpan, and Decimal type (Numeric).

Using Designer

Complete the following steps to validate the value type. The example shows TextBoxCell for which a validation error occurs if text entered cannot be converted to a numeric value.

  1. Select a cell whose value needs to be validated (for example, textBoxCell1).
  2. From the Properties window, select the Validators property and click the ... button.
  3. From the displayed CellValidator collection editor, select RequiredTypeValidator from the top-left combo box and click the Add button.
  4. From the Members list, confirm that RequiredTypeValidator has been selected.
  5. Select the RequiredType property from the property grid and select datatype Decimal that shows numeric values.
  6. Select the Actions property from the property grid and click the ... button.
  7. Add LineNotify in the displayed CellValidateAction collection editor.
  8. Click the OK button and close the CellValidateAction collection editor.
  9. Click the OK button and close thenCellValidator collection editor.
  10. Change the document window tab of the designer to Runtime.
  11. Enter text that is not numeric, move focus from the cell, and confirm that the validation error is displayed.

Using Code

The following code displays a validation error when the value is not an Integer type.

[VB]

Imports GrapeCity.Win.MultiRow

Dim textBoxCell1 As New TextBoxCell()
textBoxCell1.Value = "Hello"

Dim requiredTypeValidator1 As New RequiredTypeValidator()
requiredTypeValidator1.RequiredType = GetType(Decimal)
requiredTypeValidator1.Actions.Add(New LineNotify())
textBoxCell1.Validators.Add(requiredTypeValidator1)

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

[CS]

using GrapeCity.Win.MultiRow;

TextBoxCell textBoxCell1 = new TextBoxCell();
textBoxCell1.Value = "Hello";

RequiredTypeValidator requiredTypeValidator1 = new RequiredTypeValidator();
requiredTypeValidator1.RequiredType = typeof(decimal);
requiredTypeValidator1.Actions.Add(new LineNotify());
textBoxCell1.Validators.Add(requiredTypeValidator1);

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

Validation of Numerical Values Including Commas

You can convert the string representation of a number to an integer equivalent and perform validation for that converted vaue, by setting the RequiredTypeValidator.ParsingEnabled property to True. If the RequiredTypeValidator.ParsingEnabled property is set to True, you can use the FormatProvider property to specify the culture.

Using Code

The following code validates a numerical value with commas entered in the cell.

[VB]

Imports System.Globalization
Imports GrapeCity.Win.MultiRow

Dim textBoxCell1 As New TextBoxCell()
textBoxCell1.Style.Format = "#,#00"
textBoxCell1.ValueType = GetType(Int32)
Dim requiredTypeValidator1 As New RequiredTypeValidator()
requiredTypeValidator1.Actions.Add(New LineNotify())
requiredTypeValidator1.RequiredType = GetType(Decimal)
requiredTypeValidator1.ParsingEnabled = True
requiredTypeValidator1.FormatProvider = CultureInfo.CurrentCulture
textBoxCell1.Validators.Add(requiredTypeValidator1)

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


[CS]

using System.Globalization;
using System.Globalization;
using GrapeCity.Win.MultiRow;

TextBoxCell textBoxCell1 = new TextBoxCell();
textBoxCell1.Style.Format = "#,#00";
textBoxCell1.ValueType = typeof(Int32);
RequiredTypeValidator requiredTypeValidator1 = new RequiredTypeValidator();
requiredTypeValidator1.Actions.Add(new LineNotify());
requiredTypeValidator1.NullIsValid = true;
requiredTypeValidator1.RequiredType = typeof(Decimal);
requiredTypeValidator1.ParsingEnabled = true;
requiredTypeValidator1.FormatProvider = CultureInfo.CurrentCulture;
textBoxCell1.Validators.Add(requiredTypeValidator1);

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

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options