How do I get a combobox to scroll using arrow keys?

I have written a Windows Form Application where I have a form that has a ComboBox control. When using the Mouse I can scroll through the list and select the record I require with no problem. Unfortunately my user wants to be able to use the up / down arrow keys. This doesn't soon as I touch either key the record is selected and control returns to the form.

I have tried adding code to the KeyDown / KeyUp to replicate what I think the scrolling mouse would do but this doesn't work either!

I have copied the code below for reference.

Private Sub cmbCustomerName_KeyDown(sender As Object, e As KeyEventArgs) Handles cmbCustomerName.KeyDown

        Dim items As Integer = cmbCustomerName.Items.Count
        Dim i As Integer

        i = cmbCustomerName.SelectedIndex

        Select Case e.KeyCode
            Case Keys.Down
                cmbCustomerName.Text = cmbCustomerName.Items.Item(i + 1).ToString
            Case Keys.Up
                If i <> 0 Then
                    cmbCustomerName.Text = cmbCustomerName.Items.Item(i - 1).ToString
                End If
            Case Keys.Left

            Case Keys.Right

            Case Keys.Enter
        End Select

    End Sub
ABM SupportIT SupportAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Works fine for me.  Although I'm using VS2008.  When I populate a combobox with data I can scroll thru it with the up / down arrow keys, without having to code anything.
>as soon as I touch either key the record is selected and control returns to the form.

What code do you have in which event which selects the record and closes the form? I am guessing you have another key press event which needs to ignore the up/down keys.
ABM SupportIT SupportAuthor Commented:
Hi CodeCruiser

The only other events that relate to cmbCustomerName that are used are as follows:


Are you saying that either / both of these need to be changed?


Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

As you said that as soon as you press a key, record is selected and form is closed so there must be an event at form level which is doing that.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ABM SupportIT SupportAuthor Commented:
Hi CodeCruiser

You were spot on, the code within the cmbCustomerName_TextChanged was causing the issue! I moved this in its entirity to within the Keys.Enter case of cmbCustomerName_KeyDown and it worked first time!

Many thanks

ABM SupportIT SupportAuthor Commented:
Quick response with the answer I needed
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.