vba 如何隐藏组合框下拉列表中的列?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9138402/
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-11 15:08:31  来源:igfitidea点击:

How to hide columns in a ComboBox dropdown?

vbaexcel-vbaaccess-vbaexcel

提问by sigil

I'm building a ComboBox in an Excel userform that gets its rows from an Access table. I want to display several text fields to the user in the dropdown, but the value returned from the ComboBox should be the ID number associated with the row that the user selects (i.e. the ID column is the bound column). But I don't want to show this ID number to the user. Is there a way to hide a column in the ComboBox's dropdown, but still have that column be bound?

我正在 Excel 用户窗体中构建一个 ComboBox,它从 Access 表中获取其行。我想在下拉列表中向用户显示几个文本字段,但从 ComboBox 返回的值应该是与用户选择的行关联的 ID 号(即 ID 列是绑定列)。但我不想向用户显示这个 ID 号。有没有办法在 ComboBox 的下拉列表中隐藏一列,但仍然绑定了该列?

回答by Doug Glancy

If you have three columns - the first the ID that's hidden and the other two shown - do something like this in the Properties window:

如果您有三列 - 第一列是隐藏的 ID,另外两列显示 - 在属性窗口中执行以下操作:

enter image description here

enter image description here

Note that Combobox1.Text will get return the text in the 2nd column (the first visible one) and Combobox1.Value will give you the bound column. (The ColumnHeads setting has no bearing on the above).

请注意, Combobox1.Text 将返回第二列(第一个可见的列)中的文本,而 Combobox1.Value 将为您提供绑定列。(ColumnHeads 设置与上述无关)。