GrapeCity MultiRow Windows Forms Documentation
CompareValueValidator

You can use CompareValueValidator and validate a cell's value by comparing it to any other value. CompareValueValidator can compare only DateTime, TimeSpan, and Decimal type (Numeric) values.

Using Designer

Complete the following instructions to validate a cell's value by comparison. The example displays a validation error when the value entered in numericUpDown cell is greater than 5.

  1. Place a numericUpDownCell (for example, numericUpDownCell1).
  2. Select a cell for which to validate the value (for example, numericUpDownCell1).
  3. From the Properties window, select the Validators property and click the ... button.
  4. From the displayed CellValidator collection editor, select CompareCellValidator from the left-top combo box and click the Add button.
  5. From the Members list, confirm that CompareCellValidator has been selected.
  6. Select the ComparedValue property from the property grid and type 5.
  7. Select the ComparedOperator property from the property grid and type LessThanOrEquals.
  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 6 in numericUpDownCell1 to confirm that the validation error occurs.

Using Code

The following code illustrates the validation error when a value entered in a cell is greater than 100.

[VB]

Imports GrapeCity.Win.MultiRow

Dim textBoxCell1 As New TextBoxCell()
Dim compareValueValidator1 As New CompareValueValidator()
compareValueValidator1.RequiredType = GetType(Integer)
compareValueValidator1.ComparedValue = 100
compareValueValidator1.ComparedOperator = ValidateComparisonOperator.LessThanOrEquals
compareValueValidator1.Actions.Add(New LineNotify())
textBoxCell1.Validators.Add(compareValueValidator1)

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

[CS]

using GrapeCity.Win.MultiRow;

TextBoxCell textBoxCell1 = new TextBoxCell();

CompareValueValidator compareValueValidator1 = new CompareValueValidator();
compareValueValidator1.RequiredType = typeof(int);
compareValueValidator1.ComparedValue = 100;
compareValueValidator1.ComparedOperator = ValidateComparisonOperator.LessThanOrEquals;
compareValueValidator1.Actions.Add(new LineNotify());
textBoxCell1.Validators.Add(compareValueValidator1);

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

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options