vba 清除组合框的选择

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12697427/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 14:08:04  来源:igfitidea点击:

Clear Selections of a Combobox

excelvbacombobox

提问by Paul

I have a combobox with values that when selected, lead to other questions.

我有一个组合框,其中的值在选择时会导致其他问题。

I have a button that I want to be an "Up one level" button that clears all the following questions. It should reset the display of of the combobox to nothing, like before any options were selected, so the user can make a selection.

我有一个按钮,我想成为“上一级”按钮,可以清除以下所有问题。它应该将组合框的显示重置为空,就像在选择任何选项之前一样,以便用户可以进行选择。

I tried setting the Value = 0, the ListIndex = -1.

我尝试设置 Value = 0,ListIndex = -1。

I don't want to use "Clear" because I want to preserve the values in the combobox.

我不想使用“清除”,因为我想保留组合框中的值。

I looked through the properties of a combobox and I can't pick out which one will do what I want.

我查看了组合框的属性,但无法确定哪个可以满足我的要求。

采纳答案by Johanness

Listbox.Value=null

should do the trick.

应该做的伎俩。

回答by sybb

If you use: ComboBox1.ListIndex = -1with no list items then there will be no effect. This is a problem if you're dynamically loading the items. Use: ComboBox1.Value = Nullto clear the value as mentioned above.

如果您使用:ComboBox1.ListIndex = -1没有列表项,则不会有任何效果。如果您动态加载项目,这是一个问题。用途:ComboBox1.Value = Null清除上述值。

回答by Munim Rashid

I faced the same problem and possibly we have the same scenario.

我遇到了同样的问题,可能我们遇到了同样的情况。

I understand that you don't want to run clear method and make the current listed items vanish, but just make the combo having no value.

我知道您不想运行 clear 方法并使当前列出的项目消失,而只是使组合没有价值。

In case just before the attempt of making combo value null or blank string ("") or ListIndex=-1 you had repopulated the combo with new set of items this might happen. Before repopulating the combo with new items, you should call the clear method and then repopulate the combo with the new items and after that set the value to null or blank string ("") value.

如果就在尝试将组合值设为 null 或空白字符串 ("") 或 ListIndex=-1 之前,您已使用新的项目集重新填充组合,则可能会发生这种情况。在用新项目重新填充组合之前,您应该调用 clear 方法,然后用新项目重新填充组合,然后将值设置为 null 或空白字符串 ("") 值。