Combobox list not displaying correctly when clicked on the Arrow

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
596
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:

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
Have you got the "ColumnCount" property in Combobo1 set to 2. ????
 

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
596
Yes already "ColumnCount" property set to 2
 
Last edited:

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
596
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
 

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
596
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:

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
596
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:

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
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:

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
596
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:

Watch MrExcel Video

Forum statistics

Threads
1,100,192
Messages
5,473,050
Members
406,844
Latest member
mango22

This Week's Hot Topics

Top