Combobox list not displaying correctly when clicked on the Arrow

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
684
Hello
my combobox has 2 column counts and its items are added
When i am clicking on the same it shows the values of 1st item. i dont understand why ?
and not changing the value of idx as shown below
infact clicking on each item should display in combobox text

Code:
Private Sub ComboBox1_Click()

      Dim idx As Long
      idx = ComboBox1.ListIndex

          If idx <> -1 Then
              ComboBox1.Text = Me.ComboBox1.List(idx, 0) & "     " & Me.ComboBox1.List(idx, 1)
          End If
End Sub
NimishK
 
Last edited:

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
MickG

Have gone thru your example.
my eg. combobox has been created on userform
My result and your results are same. clicking on combobox by Down arrow of keyboard nothing happens also it shows first record.
Would like to achieve thru Combobox1_Click Event
Thanks
NimishK
 
Upvote 0
Gone thru it. Why does it not show other records while scrolling up and down in combobox by pressing down/up arrow key on keyboard. with your two examples.
Also first record is seen in all the examples
 
Last edited:
Upvote 0
if not Combobox1_click event then i tried the following with combobox1_keydown()
now able to scroll up and down but not able to see the column 2 values when scrolling up and down with up and down arrow keys
Code:
Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim idx As Long
    idx = ComboBox1.ListIndex

Select Case KeyCode
    
    Case 38 'up arrow key
            If idx = 0 Then
                idx = ComboBox1.ListCount - 1
                ComboBox1.Text = Me.ComboBox1.List(idx, 0) & "     " & Me.ComboBox1.List(idx, 1)
                KeyCode = 0
            End If
        Case 40 'down arrow key
            If idx = ComboBox1.ListCount - 1 Then
                idx = 0
                 ComboBox1.Text = Me.ComboBox1.List(idx, 0) & "     " & Me.ComboBox1.List(idx, 1)
                KeyCode = 0
            End If
    End Select
End Sub
 
Last edited:
Upvote 0
Not quit sure what you want , but the below will enable you to scroll up and down through combobox using the Up and Down Keyboard keys.
You could also try using with previous code for duel function.
Code:
Private [COLOR="Navy"]Sub[/COLOR] ComboBox1_KeyDown(ByVal KeyCode [COLOR="Navy"]As[/COLOR] MSForms.ReturnInteger, ByVal Shift [COLOR="Navy"]As[/COLOR] Integer)
Static idx [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Select[/COLOR] [COLOR="Navy"]Case[/COLOR] KeyCode
    Case 38 '[COLOR="Green"][B]up arrow key[/B][/COLOR]
           idx = idx - 1
                [COLOR="Navy"]If[/COLOR] idx < 0 [COLOR="Navy"]Then[/COLOR] idx = 0
                ComboBox1.Text = Me.ComboBox1.List(idx, 0) & "     " & Me.ComboBox1.List(idx, 1)
                KeyCode = 0
    Case 40 '[COLOR="Green"][B]down arrow key[/B][/COLOR]
             [COLOR="Navy"]If[/COLOR] idx = ComboBox1.ListCount [COLOR="Navy"]Then[/COLOR] idx = 0
                 ComboBox1.Text = Me.ComboBox1.List(idx, 0) & "     " & Me.ComboBox1.List(idx, 1)
                idx = idx + 1
                KeyCode = 0
    [COLOR="Navy"]End[/COLOR] Select
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0
MickG Thanks now on track.
Only thing is that in combobox when clicking down record on last record DataA10 DataB10. it automatically goes to 1st record. Any chances of to prevent this.
Second observation have to press twice for first time and drop down not shown
Code:
Private Sub UserForm_Initialize()
     Dim idx As Long
     idx = 0 
     ComboBox1.Text = Me.ComboBox1.List(idx, 0) & "     " & Me.ComboBox1.List(idx, 1)
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,245
Members
448,555
Latest member
RobertJones1986

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top