I'm trying to pop up a MsgBox in a GridView's CellValidating event. like this:
The event keeps firing over and over, causing the MsgBox to appear "a million" times, and finally, the MsgBox AND the Form that contains the GridView both lose the text in their title bar.
I can use a flag like this:
...and it works correctly, as long as I am trying to navigate away from the cell to some other element in the grid. If I click on any other control on the form, I get the message twice (???) but then the focus still goes to whatever other control it was I clicked on. For example, I have a "Close" button on the form, and I want the user to be able to click it to cancel their edits and not get the validation MsgBox, but instead I want to show a "Discard changes?" type dialog. Any ideas?
PS: If possible, please provide tech specs on exactly what causes the event to fire, such as the gridview losing focus, etc.
If e.Value.ToString.Length = 0 Then |
e.Cancel = True |
MsgBox("Text is required.") |
End If |
The event keeps firing over and over, causing the MsgBox to appear "a million" times, and finally, the MsgBox AND the Form that contains the GridView both lose the text in their title bar.
I can use a flag like this:
If e.Value.ToString.Length = 0 Then |
If Not validationInProgress Then |
validationInProgress = True |
e.Cancel = True |
MsgBox("Text is required.") |
validationInProgress = False |
End If |
End If |
...and it works correctly, as long as I am trying to navigate away from the cell to some other element in the grid. If I click on any other control on the form, I get the message twice (???) but then the focus still goes to whatever other control it was I clicked on. For example, I have a "Close" button on the form, and I want the user to be able to click it to cancel their edits and not get the validation MsgBox, but instead I want to show a "Discard changes?" type dialog. Any ideas?
PS: If possible, please provide tech specs on exactly what causes the event to fire, such as the gridview losing focus, etc.