GrapeCity MultiRow Windows Forms Documentation
CompareCellValidator

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

Using Designer

Complete the following steps to validate cell value by comparison. The example displays a validation error when values of two numericUpDown cells differ.

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

Using Code

The following code illustrates the validation error when a cell's value and the value in an adjacent cell differ.

[VB]

Imports GrapeCity.Win.MultiRow

Dim numericUpDownCell1 As New NumericUpDownCell()
numericUpDownCell1.Name = "numericUpDownCell1"
numericUpDownCell1.Value = 12
Dim numericUpDownCell2 As New NumericUpDownCell()
numericUpDownCell2.Name = "numericUpDownCell2"
numericUpDownCell2.Value = 12

Dim compareCellValidator1 As New CompareCellValidator()
compareCellValidator1.RequiredType = GetType(Integer)
compareCellValidator1.ComparedCellName = "numericUpDownCell2"
compareCellValidator1.ComparedOperator = ValidateComparisonOperator.Equals
compareCellValidator1.Actions.Add(New LineNotify())
numericUpDownCell1.Validators.Add(compareCellValidator1)

Dim cells As Cell() = {numericUpDownCell1, numericUpDownCell2}
GcMultiRow1.Template = Template.CreateGridTemplate(cells)
GcMultiRow1.RowCount = 10

[CS]

using GrapeCity.Win.MultiRow;

NumericUpDownCell numericUpDownCell1 = new NumericUpDownCell();
numericUpDownCell1.Name = "numericUpDownCell1";
numericUpDownCell1.Value = 12;
NumericUpDownCell numericUpDownCell2 = new NumericUpDownCell();
numericUpDownCell2.Name = "numericUpDownCell2";
numericUpDownCell2.Value = 12;

CompareCellValidator compareCellValidator1 = new CompareCellValidator();
compareCellValidator1.RequiredType = typeof(int);
compareCellValidator1.ComparedCellName = "numericUpDownCell2";
compareCellValidator1.ComparedOperator = ValidateComparisonOperator.Equals;
compareCellValidator1.Actions.Add(new LineNotify());
numericUpDownCell1.Validators.Add(compareCellValidator1);

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

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options