BUG: Setting CancelEventArgs to True is failing
We are handling the Validating event for a control. If a conditional test fails in this event handler, we set CancelEventArgs = True and call SetError on ErrorProvider :
If txtBox.Text.Trim = String.Empty Then
Me.ReviewErrorProvider.SetError(DirectCast(sender,
txtBox), "Required Field")
e.Cancel = True
There is a button on the same form as the control. Call this buttonA. When clicking on buttonA after setting CancelEventArgs = True in txtBox's validating handler, the Click Event fires for buttonA. Since we called e.Cancel = True, this event should not fire.
Now, if we add a breakpoint on the call to CancelEventArgs = True in txtBox's validating handler, buttonA's click event is blocked (the event does not fire).
So, what is it about the breakpoint that makes this work?
This has been reported as a bug to Microsoft.