Link to home
Start Free TrialLog in
Avatar of rgn2121
rgn2121Flag for United States of America

asked on

Windows Forms Control Validation and allowing form close.

I am using code in my Validating event on a ComboBox to force the user to make a choice, which works, but once the user opens the form then they have to make a choice before they can close it.  I was to check if the form is closing, then skip validation...  I use the code below to validate...
If String.IsNullOrEmpty(ComboBox1.SelectedItem) Then
            e.Cancel = True
        End If

Open in new window

SOLUTION
Avatar of JackOfPH
JackOfPH
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgn2121

ASKER

Okay..that works.  I am curious...when I use this validating event with the combo box and I click the red X to close out, the way I have it setup is that the ErrorProvider pops the little message.  But when I go to try and make a selection the drop down will open and then close right back unless I click the drop down and hold the mouse button down till I drag onto the selections.  Have you ever seen this?
 
Avatar of rgn2121

ASKER

You know...I am not sure that solution really works, because if they don't make a selection and they click another control on the form, then it will allow it because I allow ComboBox.SelectedItem=Nothing.
Is there a way to tell if the form is closing  without using API?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial