简体   繁体   English

获取组合框下拉列表中突出显示的项的值? Excel VBA

[英]Get value of the highlighted item in a combobox dropdown list? Excel VBA

The mouseover event of a combobox on my form triggers a label to become visible and show details of the currently selected combobox value. 我的表单上组合框的mouseover事件触发一个标签变为可见并显示当前所选组合框值的详细信息。 When the user clicks the down arrow to show the combobox list items available for selection, I want the label to update with details of the currently highlighted item in the dropdownlist without having to actually select it as the combobox value. 当用户单击向下箭头以显示可供选择的组合框列表项时,我希望标签更新下拉列表中当前突出显示的项的详细信息,而不必实际选择它作为组合框值。

In other words, as the user moves the mouse over the items and the highlighted item changes, I want the details in the label to update for the highlighted value. 换句话说,当用户将鼠标移到项目上并且突出显示的项目发生更改时,我希望标签中的详细信息针对突出显示的值进行更新。

So far, I have found nothing on how to do this. 到目前为止,我对如何执行此操作一无所获。 Excel obviously knows which item is highlighted, but how to access this information programmatically eludes me. Excel显然知道突出显示了哪个项目,但是如何以编程方式访问此信息使我难以理解。

Any ideas? 有任何想法吗?

If the combobox is a control then you could use the MouseMove event to get the current highlighted item. 如果组合框是控件,则可以使用MouseMove事件获取当前突出显示的项目。

Private Sub ComboBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    If ComboBox1.TopIndex > -1 Then
        Dim curIndex As Integer
        curIndex = ComboBox1.TopIndex + Application.WorksheetFunction.RoundDown(Y / 13.5, 0)
        curValue = ComboBox1.List(curIndex)
    End If
End Sub

then show the tooltip. 然后显示工具提示。
Note: 13.5 is, by my tests, the height of an item in dropdown... 注意:根据我的测试,13.5是下拉列表中某项的高度...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM