GrapeCity.Win.MultiRow Namespace > GcMultiRow Class : CellValidating Event |
<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
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.
Property | Description |
---|---|
Cancel | (Inherited from System.ComponentModel.CancelEventArgs) |
CellIndex | Gets the cell index in its parent Section. (Inherited from GrapeCity.Win.MultiRow.CellCancelEventArgs) |
CellName | Gets the cell name. (Inherited from GrapeCity.Win.MultiRow.CellCancelEventArgs) |
FormattedValue | Gets the formatted cell contents that need to be validated. |
RowIndex | Gets the index of the owner Row that the event occurs for. (Inherited from GrapeCity.Win.MultiRow.CellCancelEventArgs) |
Scope | Gets the cell area that the event occurs for. (Inherited from GrapeCity.Win.MultiRow.CellCancelEventArgs) |
SectionIndex | Gets the index of the owner Section that the event occurs for. (Inherited from GrapeCity.Win.MultiRow.CellCancelEventArgs) |
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.
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
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