BlakeMcKenna
asked on
Checking for mouseclicks outside of CellValidating Event?
My Windows Form has a DataGridView (dgv) in which some of the cells cannot be empty. So...once a cell has focus and then another action is taken, for instance clicking on a button, the CellValidating Event fires first. Below is the event:
This code works to a point! As long as the cell is empty, this Event continues to fire regardless how many times I click a button or basically just put focus on another control. Is there a way to break out of the Event and capture another keystroke/mouseclick?
Thanks!
Private Sub dgvCompression_CellValidating(sender As Object, e As DataGridViewCellValidatingEventArgs) Handles dgvCompression.CellValidating
Try
Dim newInteger As Integer
EH.ErrorMessage = String.Empty
Select Case e.RowIndex
Case e.RowIndex > 0
Select Case e.ColumnIndex
Case 1 'Output Cell
If Not Integer.TryParse(e.FormattedValue.ToString(), newInteger) OrElse newInteger < 0 Then
e.Cancel = True
EH.ErrorMessage = "Cell cannot be empty!" & "~I"
End If
End Select
End Select
Catch ex As Exception
EH.ErrorMessage = "frmCalibration_3/dgvCompression_CellValidating() - " & ex.Message & "...Contact Engineering!" & "~E"
End Try
EH.ProcessMessages(Me, sbr, EH.ErrorMessage)
End Sub
This code works to a point! As long as the cell is empty, this Event continues to fire regardless how many times I click a button or basically just put focus on another control. Is there a way to break out of the Event and capture another keystroke/mouseclick?
Thanks!
ASKER
EH.ProcessMessages displays messages using a MessageBox.Show method. Doesn't sound like there's a good work-around...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I actually found a way to handle the empty cells. It's not my first choice but it does accomplish what I need it to do. I will definitely look into what you said sudheeshthegreat....especi ally the ErrorText possibility.
This event occurs when a cell loses input focus, enabling content validation.
What are you doing in EH.ProcessMessages? For instance, if you set the focus to a grid, and provide a MessageBox, it would cause the cell to get focus and lose it again, causing the event to keep triggering over and over again.