I have 2 projects both using the same methods of cell validation (based on Infragistice Knowlwdge Base article KB01747). In the first project it works fine. However in the second the BeforeCellDeactivation event will not fire. Therefore the user is not directed back to the cell to enter the proper data. The code between the 2 projects are almost identical. The difference primarily being the criteria the data is validated against. But that should have no effect on the event not firing.
Code snipits from the failing project:
THIS FIRES properly & when it should:
UGridWeights.BeforeCellUpdate
e.Cell.Column.Key
"WeightClass"
c_cellBadCell = e.Cell
Select
Sub
This is the code of the Event that does not fire:
Private
Sub UGridWeights_BeforeCellDeactivate(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles UGridWeights.BeforeCellDeactivate
If Not c_cellBadCell Is Nothing Then
e.Cancel =
True
UGridWeights.ActiveCell = c_cellBadCell
UGridWeights.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.EnterEditMode _
,
False _
False)
c_cellBadCell =
Nothing
xBadCell =
End If
End Sub
The Validation code:
Private Function ValidWeight(ByVal e As Infragistics.Win.UltraWinGrid.BeforeCellUpdateEventArgs) As Boolean
Try
If e.NewValue = Nothing Then
MessageBox.Show(
"The Weight Class in nothing.", "Weight Class", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf Not IsNumeric(e.NewValue) Then
"Please re-enter the Weight Class and be sure it is a numeric entry greater than zero (0).", "Weight Class", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Return False
ElseIf e.NewValue <= 0 Then
ElseIf CInt(e.NewValue) > 300 Then
If (MessageBox.Show("You have entered an abnormally high Weight Class. Do you want to keep this weight?.", "Weight Class", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) = Windows.Forms.DialogResult.No) Then
Else
Return True
Catch err As Exception
"Please be sure your entry is an Interger and that it is a Quantity equal to or greater than 0 (zero) for this item", "Weight Class", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Function
Any Help you can is getting this to work would be greatly appreciated.
Thanks
Gary
The only reason I can think of why the event would not fire is if it's not hooked up properly. Perhaps the code that hooks the event in the grid is not getting called or was accidentally removed.
I'm not sure what you mean by the code that hooks the event in the grid.
But a little more info might help. When the user tries to click off the active cell the BeforeCellDeactivate event fires properly. First the BeforeCellUpdate fires then the BeforeCell Deactivate fires.
However I'm deactivating the cell through code by inserting a new line in the grid. I cause the cell's BeforeCellUpdate event to fire by calling the grid's updatedata(). In the cell's before update event i validate the data. Regardless if the data is good or bad a routine to add new lines is called and this is where i expected that Cell's BeforeCellDeactive comes in as the grid tries to set the pointer away from the cell in question to the new line. If the function that validates the data determines that is is bad the code in the BeforeCellDeactive event will prevent it from continuing, so the KB article seems to imply. In fact in another 2 projects this works fine, but not in this one.
Hi Gary,
So the event is not firing when you call UpdateData? Maybe you need to call PerformAction(ExitEditMode) first to force the cell to exit edit mode before updating the data.