[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Combobox validation routine in a loop

Posted on 2009-04-29
9
Medium Priority
?
541 Views
Last Modified: 2012-05-06
I found some code that works to validate a combobox in VB.NET 2008.  However, the MessageBox keeps popping up over and over.  It seems that the Enter key I use to close it fires the event over again, so I am in a loop.  How can I turn off the loop?

I also tried PreviewKeyDown, which makes the box appear only twice, which is better, but still not great.

Thanks
If e.KeyCode = Keys.Enter Then
            If CUST_IDComboBox.FindStringExact(CUST_IDComboBox.Text) = -1 Then
                MessageBox.Show("You entered an Invalid Number!")
                Return
            End If
        End If

Open in new window

0
Comment
Question by:nordicgirl
  • 5
  • 2
  • 2
9 Comments
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24266779
Can you explain us what you want to achieve in your code?

Does this code check the entry in the combobox if it is in the listitem?
0
 

Author Comment

by:nordicgirl
ID: 24266832
Yes, exactly.  The combobox lists customer numbers.  The users have the option of typing in a number, because there are too many numbers to require the users to scroll down through all of them.  The code checks to make sure the number is a valid number from this list.
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24266863
No need for this validation just set the AutcompleteMode  property of the combobox to suggest and AutocompleteSource to listitems.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:nordicgirl
ID: 24269433
Well, unfortunately, our managers have may of these numbers memorized and just type them in without looking.  If I type in an invalid number and press enter, there is just no response from the combobox.  That would be warning enough of a typo, but my boss wants an error message.  So therein lies the need. : )
0
 

Author Comment

by:nordicgirl
ID: 24272282
I got it to work on the Key Down Event.
0
 
LVL 3

Expert Comment

by:RobbP
ID: 24273074
Note - make sure the 'CausesValidation' property is set to false on the button in question.
0
 

Author Comment

by:nordicgirl
ID: 24273520
The default value for 'Causes Validation' for a combobox is True.  What does this property do and why should I set it to False?

Thanks.
0
 
LVL 3

Accepted Solution

by:
RobbP earned 150 total points
ID: 24274002
It will force all validators to run when it is clicked (Whatever the relevant events are), you only want it to validate when the subit action is invoked eg a submit button.

So by setting this to false it should prevent validators to invoke ie you shouldnt get the validator popping up everytime - did you give it a go?
0
 

Author Comment

by:nordicgirl
ID: 24275430
I did, but it didn't seem to make a difference.  In my case, it seems to be related to the focus.  If I click the mouse on the OK button of the message box, it goes away SOMETIMES. It seems to still be focused on the main screen , not the message box.  

Now at home, the keyup event has me pressing the enter key forever, and the keydown event has me doing it 3 times, (2 messasge boxes)  and then the messagebox goes away.  wierd.  

To tell you the truth, I don't know why it started working.( this was earlier today at work). i will have to keep an eye on it.

Thanks.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Integration Management Part 2
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month18 days, 14 hours left to enroll

834 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