简体   繁体   English

ComboBox.Dropdown方法仅显示一个列表项

[英]ComboBox.Dropdown Method only shows one list item

I'm using a ComboBox in excel (vba) that adds items to the list based on what is typed (near matches) so that if what they are typing already exists in the data range, they can see it and click. 我在excel(vba)中使用了一个ComboBox,它根据键入的内容(接近匹配项)将项目添加到列表中,因此,如果它们所键入的内容已存在于数据范围内,则他们可以查看并单击。

This is all working fine except for the method ComboBox1.DropDown, which is supposed to display the list. 除了方法ComboBox1.DropDown可以显示列表之外,其他所有方法都工作正常。 Unfortunately it only shows one item with the scroll buttons. 不幸的是,它只显示带有滚动按钮​​的一项。 Clicking the drop down button or pressing f4 shows the correct number of lines determined by the box's properties. 单击下拉按钮或按f4将显示由框的属性确定的正确行数。

I've searched and searched, any clue how to show all items in the list automatically? 我已经搜索了,有什么线索如何自动显示列表中的所有项目?

This is my first question on SO, please advise if tagged incorectly. 这是我关于SO的第一个问题,如果标签有误,请告知。

edit: ActiveX control, .listRows and .listFillRange do not seem to help 编辑:ActiveX控件,.listRows和.listFillRange似乎没有帮助

I've been calling .DropDown in a custom Sub that creates the list, I needed to change it so it is now the last line in ComboBox1_Change(). 我一直在创建列表的自定义Sub中调用.DropDown,我需要对其进行更改,因此它现在是ComboBox1_Change()的最后一行。

Not sure why it acts differently in _change() than it did in my Sub (that was called by _change())! 不知道为什么它在_change()中的行为不同于我在Sub中的行为(被_change()称为)!

I think that this is actually related to using the .clear method and then calling .Dropdown, it doesn't recalculate how many lines to show. 我认为这实际上与使用.clear方法然后调用.Dropdown有关,它不会重新计算要显示的行数。 I may need to just keep them in separate Subs Thanks for your responses @PatricK 我可能需要将它们放在单独的Subs中。感谢您的回复@PatricK

Edit: Not solved, it now works correctly with the first "change" more letters typed causes the rest of the list to stay un-cleared while the first row is updated and has the scroll buttons. 编辑:尚未解决,它现在可以与第一个“更改”一起正常工作,输入的更多字母会导致在更新第一行并具有滚动按钮​​时,列表的其余部分保持未清除状态。 I wish I knew exactly how these methods are written and when they get executed. 我希望我确切地知道这些方法是如何编写的以及何时执行。

ComboBox1.Visible = False
ComboBox1.Visible = True
ComboBox1.Activate
If ComboBox1.ListCount > 0 Then
   ComboBox1.DropDown
End If

This code seems to do the trick, at least more than one line is diplayed, and the list is becomes shorter if items are removed, unlike before. 这段代码似乎可以解决问题,至少删除了多行,如果删除了项目,则列表变得更短,这与以前不同。

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

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