Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Windows Forms Control Validation and allowing form close.

Posted on 2009-04-14
4
Medium Priority
?
443 Views
Last Modified: 2013-11-26
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

0
Comment
Question by:rgn2121
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 15

Assisted Solution

by:JackOfPH
JackOfPH earned 200 total points
ID: 24135653
TRy this...

If ComboBox1.Selectedindex =-1 Then
            e.Cancel = True
End If


Or this

If ComboBox1.Selecteditem is nothing Then
            e.Cancel = True
End If
0
 
LVL 12

Author Comment

by:rgn2121
ID: 24135702
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?
 
0
 
LVL 12

Author Comment

by:rgn2121
ID: 24135738
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?
0
 
LVL 12

Accepted Solution

by:
rgn2121 earned 0 total points
ID: 24135806
Okay...I couldn't work around what you had given me so that other controls could be clicked and it would validate, but it wouldn't on the form_Closing..  I finally found that I can leave my code alone in the validating event and then in my form_Closing event I can set e.Cancel = False.  This will allow my form to close when the click the red x no matter what the validation says....
 
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question