GrapeCity MultiRow Windows Forms Documentation
CellValidating Event
Example 


Occurs when a cell loses input focus, which enables content validation.
Syntax
<SRDescriptionAttribute("Occurs when a cell loses input focus, enabling content validation. ")>
<FeatureAttribute(Name="DataTranslation", Version="v5.0")>
<SRCategoryAttribute("Focus")>
Public Event CellValidating As EventHandler(Of CellValidatingEventArgs)
Dim instance As GcMultiRow
Dim handler As EventHandler(Of CellValidatingEventArgs)
 
AddHandler instance.CellValidating, handler
[SRDescription("Occurs when a cell loses input focus, enabling content validation. ")]
[Feature(Name="DataTranslation", Version="v5.0")]
[SRCategory("Focus")]
public event EventHandler<CellValidatingEventArgs> CellValidating
Event Data

The event handler receives an argument of type CellValidatingEventArgs containing data related to this event. The following CellValidatingEventArgs properties provide information specific to this event.

PropertyDescription
Cancel (Inherited from System.ComponentModel.CancelEventArgs)
CellIndexGets the cell index in its parent Section. (Inherited from GrapeCity.Win.MultiRow.CellCancelEventArgs)
CellNameGets the cell name. (Inherited from GrapeCity.Win.MultiRow.CellCancelEventArgs)
FormattedValueGets the formatted cell contents that need to be validated.  
RowIndexGets the index of the owner Row that the event occurs for. (Inherited from GrapeCity.Win.MultiRow.CellCancelEventArgs)
ScopeGets the cell area that the event occurs for. (Inherited from GrapeCity.Win.MultiRow.CellCancelEventArgs)
SectionIndexGets the index of the owner Section that the event occurs for. (Inherited from GrapeCity.Win.MultiRow.CellCancelEventArgs)
Remarks

Handle the CellValidated event to perform post validation processing. Canceling this event cancels the changes to the current cell. When this event is canceled in data bound mode, the new value is not pushed to the underlying data source. When this event is canceled in virtual mode, the CellValuePushed event is not raised.

The CellValidating event only fires when losing input focus (before leaving the current cell) or when GcMultiRow validates. The default key setting assigns end edit without leaving the current cell action to the "Enter" key. So the CellValidating event cannot be fired when pressing the "Enter" key. If you want the CellValidating event to fire, assign the "Enter" key to the SelectionActions.MoveToNextCell or SelectionActions.MoveDown action.

Example
The following code example shows how to use this event to validate the cell's value. To run this example, create a windows form, and add a GcMultiRow control to the form. Add a NumericUpDownCell named "Age" to the MultiRow controls template. Add the event handle of this event and copy the following code into the event handler. Input some invalid values and try to move the focus.
void gcMultiRow1_CellValidating(object sender, CellValidatingEventArgs e)
        {
            if (e.CellName == "Age")
            {
                int age = int.Parse(e.FormattedValue.ToString());
                if (age < 0 || age > 100)
                {
                    e.Cancel = true;

                    // Set error text to why the cell validating failed.
                    this.gcMultiRow1[e.RowIndex, e.CellIndex].ErrorText = "The age should be greater than 0 and less than 
100.";

                    this.gcMultiRow1.EndEdit();
                }
                else
                {
                    this.gcMultiRow1[e.RowIndex, e.CellIndex].ErrorText = string.Empty;
                }
            }
        }
Private Sub gcMultiRow1_CellValidating(ByVal sender As Object, ByVal e As CellValidatingEventArgs) Handles 
gcMultiRow1.CellValidating
        If e.CellName = "Age" Then
            Dim age As Integer = Integer.Parse(e.FormattedValue.ToString())
            If age < 0 OrElse age > 100 Then
                e.Cancel = True

                ' Set error text to why the cell validating failed.
                Me.gcMultiRow1(e.RowIndex, e.CellIndex).ErrorText = "The age should greater than 0 and less than 100."

                Me.gcMultiRow1.EndEdit()
            Else
                Me.gcMultiRow1(e.RowIndex, e.CellIndex).ErrorText = String.Empty
            End If
        End If
    End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

GcMultiRow Class
GcMultiRow Members

 

 


Copyright © GrapeCity, inc. All rights reserved.