Reputation: 15457
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?
Upvotes: 2
Views: 3053
Reputation: 870
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
Upvotes: 0
Reputation: 2831
All you actually need is
e.Cancel = False;
in your FormClosing event.
Upvotes: 5
Reputation: 21
I had the same issues, but then I solved it by
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
Upvotes: 0