How to display second column in ComboBox after sel

2019-09-14 23:18发布

I can click on my ComboBox and see the values of Column1 and Column2, but after I click on off the ComboBox, the value in Column1 is always displayed and I want the value of Column2 displayed.

enter image description here

enter image description here

I tried this:

        With ComboBox2
            .Value = "None"
            .ColumnHeads = True
            .ColumnCount = 2
            .ColumnWidths = "50;100"
            .RowSource = "SetupQuestions!A42:B48"
            .BoundColumn = 2
        End With

That didn't set the value as I thought it would.

I tried this:

Private Sub ComboBox2_AfterUpdate()
    ComboBox2.Value = ComboBox2.Column(2)
End Sub

That didn't set the value as I thought it would.

How can I force the ComboBox to display the value in Column2 after a selection is made?

3条回答
Lonely孤独者°
2楼-- · 2019-09-14 23:47

Argh! It's not .Value

It's .Text

Private Sub ComboBox2_AfterUpdate()
    Me.ComboBox2.text = Me.ComboBox2.Column(1)
End Sub
查看更多
够拽才男人
3楼-- · 2019-09-14 23:50

If you are only concerned with appearances, there is a workaround

Private Sub ComboBox2_Click()

With ComboBox2
    .Text = .List(.ListIndex, 0) & " | " & .List(.ListIndex, 1)
End With

End Sub
查看更多
欢心
4楼-- · 2019-09-15 00:07

I just came across here because I was looking to solve this too. but other people's response helped me find the answer. If you haven't gotten it yet, here is my solution.

Private Sub ComboBox_AfterUpdate()

  ComboboxList.Text = ComboboxList.Column(0) & " " & ComboboxList.Column(1)

End Sub
查看更多
登录 后发表回答