GrapeCity MultiRow Windows Forms Documentation
Validation using Control Events

Values entered into the cell can be validated by two types of events, similar to the validation performed for the input into the control. Similarly, you can also perform validation for each row.

Notify Validation Error Using Icon and Tooltip

If the value entered by the user in a cell contains an error, you can display an error icon in that cell or in its associated row. Also, the user can confirm error details by placing the pointer over the error icon.

Notify Validation Error using Icon and Tooltip

For instructions, refer to Displaying Error Messages.

Notify Validation Error Using Balloon Tip

If the value entered by the user contains an error, you can display validation error details in a balloon tip, which can prompt the user for an appropriate value. This validation indicator can be used if you are using the always edit mode (GcMultiRow.EditType=EditType.AlwaysEdit), that is, when the error icon or error tip cannot be displayed.

Notify Validation Error by BalloonTip

Using Code

The following code notifies the user of a validation error using a balloon tip when more than five characters are entered in the first textboxcell, and asks the user to change the value. To run this sample code, you need to keep the ToolTip component (ToolTip1) on the form.

[VB]

Imports GrapeCity.Win.MultiRow

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    GcMultiRow1.ShortcutKeyManager.Unregister(Keys.Enter)
    GcMultiRow1.ShortcutKeyManager.Register(SelectionActions.MoveToNextCell, Keys.Enter)
End Sub

Private Sub GcMultiRow1_CellValidating(ByVal sender As System.Object, ByVal e As GrapeCity.Win.MultiRow.CellValidatingEventArgs) Handles GcMultiRow1.CellValidating
    Dim gcMultiRow As GcMultiRow = DirectCast(sender, GcMultiRow)

    If (e.CellIndex = 0) AndAlso (e.RowIndex = 0) Then
        Dim currentCellRect As Rectangle = gcMultiRow.GetCellDisplayRectangle(e.RowIndex, e.CellIndex)
        Dim value As String = TryCast(e.FormattedValue, String)
        Dim hasError As Boolean = False

        If (Not value Is Nothing) AndAlso (value.Length > 5) Then
            Me.ToolTip1.ToolTipIcon = ToolTipIcon.Error
            Me.ToolTip1.ToolTipTitle = "Validation Error"
            Me.ToolTip1.IsBalloon = True
            Me.ToolTip1.SetToolTip(gcMultiRow.EditingControl, "dummy")
            Me.ToolTip1.Show("The value entered has more than 5 characters.", gcMultiRow.EditingControl, 0, currentCellRect.Height)
            hasError = True
            e.Cancel = True
        End If

        ' Remove balloon tip if there is no error.
        If (hasError = False) Then
            Me.ToolTip1.Hide(Me)
            Me.ToolTip1.RemoveAll()
        End If
    End If
End Sub

[CS]

using GrapeCity.Win.MultiRow;

private void Form1_Load(object sender, EventArgs e)
{
    gcMultiRow1.ShortcutKeyManager.Unregister(Keys.Enter);
    gcMultiRow1.ShortcutKeyManager.Register(SelectionActions.MoveToNextCell, Keys.Enter);
}

private void gcMultiRow1_CellValidating(object sender, CellValidatingEventArgs e)
{
    GcMultiRow gcMultiRow = (GcMultiRow)sender;

    if (e.CellIndex == 0 && e.RowIndex == 0)
    {
        Rectangle currentCellRect = gcMultiRow.GetCellDisplayRectangle(e.RowIndex, e.CellIndex);

        string value = (string)e.FormattedValue;
        bool hasError = false;
        if (value != null && value.Length > 5)
        {
            this.toolTip1.ToolTipIcon = ToolTipIcon.Error;
            this.toolTip1.ToolTipTitle = "Validation Error";
            this.toolTip1.IsBalloon = true;
            this.toolTip1.SetToolTip(gcMultiRow.EditingControl, "dummy");
            this.toolTip1.Show("The value entered has more than 5 characters.", gcMultiRow.EditingControl, 0, currentCellRect.Height);
            hasError = true;
            e.Cancel = true;
        }
        // Remove balloon tip if there is no error.
        if (hasError == false)
        {
            this.toolTip1.Hide(this);
            this.toolTip1.RemoveAll();
        }
    } 
}

Modify Value

You can use the following to modify the value entered by the user depending on the timing.

When over-writing the value of a cell whose editing has been completed When over-writing the value of a cell which is in edit mode
GcMultiRow.SetValue method or Cell.Value property GcMultiRow.EditingControl.Text property or Cell Edit Control specific member
The editing state of a cell can be confirmed using the GcMultiRow.IsEditing property.

Restrict Input of Value

The Cell Edit Control allows you to restrict the input value. For example, TextBoxCell has a restriction of maximum length, NumericUpDownCell takes numeric values only, and MaskedTextBoxCell restricts formatted strings.

Value and DataSource

A GcMultiRow.DataError event occurs if the entered value does not match the data type of the datasource.

See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options