Why is it when I first come to my window which is a form with a user control and combo box set to blank. I can click Cancel without any problem and window closes. However, if I touch the combo box and then leave it blank and I try to click Cancel the cancel event doesn't fire?
Asked
Active
Viewed 2,805 times
4 Answers
0
I had the same issues, but then I solved it by
- Setting the CausesValidation property of the button to False.
- Re-setting all the controls on the form.
Closing the Form.
while (Controls.Count > 0) { Controls[0].Dispose(); } this.Close();
I added this code to the Button_Click() event as well as the From_Closing event. Regards, Kshitij Thube

Kshitij Thube
- 21
- 2
0
Rod's answer leads to the solution.
If the forms (container of the error-provider) AutoValidate
-property is set to EnableAllowFoucsChange
, button events are handled and in the Click
-Event now it is possible to check if the form has invalid children:
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
If Not ValidateChildren() Then Exit Sub
End sub

DrMarbuse
- 804
- 11
- 30