You can use the MessageBoxNotify class to notify the user of a validation error by displaying a message box. You can change the title, text, and icon of the message box.
|
The only button in the message box that is displayed by MessageBoxNotify is the OK button. |
Using the Designer
Use the following steps to use a message box 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 RequiredFieldValidator from the left-top combo box and click the Add button.
- Select the Actions property from the property grid and click the ... button.
- Add MessageBoxNotify in the displayed CellValidateAction collection editor.
- From the Members list, confirm that MessageBoxNotify has been selected.
- Select the Caption property from the property grid and enter the title.
- Set the DoActionReason property in the property grid to CellValidating.
- Set the Icon property in the property grid to Hand.
- Select the Message property from the property grid and type the description.
- 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.
- Confirm that the validation error is displayed when you move to the next cell without making changes in textBoxCell1.
Using Code
The following code displays the validation error in a message box when a String type cell value is blank.
[VB]
Imports GrapeCity.Win.MultiRow
Dim textBoxCell1 As New TextBoxCell()
Dim requiredFieldValidator1 As New RequiredFieldValidator()
Dim messageBoxNotify1 As New MessageBoxNotify()
messageBoxNotify1.Caption = "Title"
messageBoxNotify1.DoActionReason = ValidateReasons.CellValidating
messageBoxNotify1.Icon = MessageBoxIcon.Hand
messageBoxNotify1.Message = "Error"
requiredFieldValidator1.Actions.Add(messageBoxNotify1)
textBoxCell1.Validators.Add(requiredFieldValidator1)
Dim cells As Cell() = {textBoxCell1}
GcMultiRow1.Template = Template.CreateGridTemplate(cells)
GcMultiRow1.RowCount = 10
|
[CS]
using GrapeCity.Win.MultiRow;
TextBoxCell textBoxCell1 = new TextBoxCell();
RequiredFieldValidator requiredFieldValidator1 = new RequiredFieldValidator();
MessageBoxNotify messageBoxNotify1 = new MessageBoxNotify();
messageBoxNotify1.Caption = "Title";
messageBoxNotify1.DoActionReason = ValidateReasons.CellValidating;
messageBoxNotify1.Icon = MessageBoxIcon.Hand;
messageBoxNotify1.Message = "Error";
requiredFieldValidator1.Actions.Add(messageBoxNotify1);
textBoxCell1.Validators.Add(requiredFieldValidator1);
Cell[] cells = { textBoxCell1 };
gcMultiRow1.Template = Template.CreateGridTemplate(cells);
gcMultiRow1.RowCount = 10;
|
See Also