How do I get a combobox to scroll using arrow keys?
Posted on 2014-07-16
I have written a vb.net 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 work....as 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
cmbCustomerName.Text = cmbCustomerName.Items.Item(i + 1).ToString
If i <> 0 Then
cmbCustomerName.Text = cmbCustomerName.Items.Item(i - 1).ToString