You can use the ValueProcess class to perform the processes of retaining, deleting, or restoring the previous value when a validation error occurs. ValueProcess is executed when the cell validation or cell editing state ends.
Using the Designer
Use the following steps to use the value process for cell validation.
- Select a cell value to validate (for example, textBoxCell1).
- From the Properties window, select the Validators property and click the ... button.
- From the displayed CellValidator collection editor, select IncludeListValidator from the left-top combo box and click the Add button.
- From the Members list, confirm that IncludeListValidator has been selected.
- Select the Candidates property from the property grid and click the ... button.
- Set the required string in the displayed String Collection Editor.
For example:
- Click the OK button to close the window.
- Select the Actions property from the property grid and click the ... button.
- Add ValueProcess in the displayed CellValidateAction collection editor.
- From the Members list, confirm that ValueProcess has been selected. In the property grid, set the DoActionReason property to CellValidating, and ValueProcessOption property to Clear.
- Click the OK button to close the CellValidateAction collection editor.
- Click the OK button to close the CellValidator collection editor.
- Change the document window tab of the designer to Runtime.
- Enter Washington in textBoxCell1 to confirm that the validation error occurs and the entered value gets deleted, when you move to another cell.
Using Code
The following code illustrates the validation error, and deletes the entered value when a string other than "New York" or "California" is entered in the cell.
[VB]
Imports GrapeCity.Win.MultiRow
Dim textBoxCell1 As New TextBoxCell()
Dim includeListValidator1 As New IncludeListValidator()
Dim valueProcess1 As New ValueProcess()
valueProcess1.DoActionReason = ValidateReasons.CellValidating
valueProcess1.ValueProcessOption = ValueProcessOption.Clear
includeListValidator1.Candidates = New String() {"New York", "California"}
includeListValidator1.Actions.Add(valueProcess1)
textBoxCell1.Validators.Add(includeListValidator1)
Dim cells As Cell() = {textBoxCell1}
GcMultiRow1.Template = Template.CreateGridTemplate(cells)
GcMultiRow1.RowCount = 10
|
[CS]
using GrapeCity.Win.MultiRow;
TextBoxCell textBoxCell1 = new TextBoxCell();
IncludeListValidator includeListValidator1 = new IncludeListValidator();
ValueProcess valueProcess1 = new ValueProcess();
valueProcess1.DoActionReason = ValidateReasons.CellValidating;
valueProcess1.ValueProcessOption = ValueProcessOption.Clear;
includeListValidator1.Candidates = new string[] { "New York", "California" };
includeListValidator1.Actions.Add(valueProcess1);
textBoxCell1.Validators.Add(includeListValidator1);
Cell[] cells = { textBoxCell1 };
gcMultiRow1.Template = Template.CreateGridTemplate(cells);
gcMultiRow1.RowCount = 10;
|
|
If the DoActionReason property is set to EndEdit, then only the timing at which the value process is executed differs from when it is set to CellValidating, but the end result is the same. |
See Also