vba 组合框可以在其文本框部分显示多于一列吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6867461/
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
Can a combobox present more then one column on its textbox part?
提问by eagleye
I have a two column list in my combobox and when I choose one of the items in it using the drop down list, it stores (what I see in the textbox part of the combobox) only the value I selected (wether it's the one on the right or left column according to boundcolumn)
我的组合框中有一个两列列表,当我使用下拉列表选择其中的一项时,它仅存储(我在组合框的文本框部分看到的内容)我选择的值(无论是根据 boundcolumn 的右列或左列)
My question is: Is there a way to store(or present-that is my goal) in the textbox part of the combobox, both of the columns of one row selected?
我的问题是:有没有办法在组合框的文本框部分存储(或呈现——这是我的目标),选择一行的两列?
For example: [column1] Daniel [column2] Smith. And in the textbox I want: Daniel Smith (and not just Daniel, or Smith on they're own)
例如:[column1] Daniel [column2] Smith。在我想要的文本框中:丹尼尔史密斯(不仅仅是丹尼尔,或者史密斯自己)
回答by Clijsters
What you describe is theoretically possible, but with restrictions.
你所描述的理论上是可能的,但有限制。
Even when you didn't ask for that, here comes my idea:
即使你没有要求,我的想法也来了:
Like described hereyou can change your ComboBox's text
without changing its value
. This allows you to 'store' the underlying value while displaying both columns in one.
就像这里描述的那样,你可以改变你的 ComboBoxtext
而不改变它的value
. 这允许您“存储”基础值,同时将两列显示为一列。
Listen on the SelectedIndexChanged Event
and change the text
property as follows:
侦听SelectedIndexChanged Event
并更改text
属性,如下所示:
Sub ComboBox1_SelectedIndexChanged()
ComboBox1.Text = ComboBox1.Column(0) & "-" & ComboBox1.Column(1)
End Sub
(This is only a basic example.) Can't test it right now, but in .Net you can use CType
to explicitly convert the sender
argument to a ComboBox variable and access it this way.
(这只是一个基本示例。)现在无法测试,但在 .Net 中,您可以使用CType
将sender
参数显式转换为 ComboBox 变量并以这种方式访问它。
The Boundcolumn
property can't be changed to multiple values. You can try to use VbTab
as a delimiter in the text field but i'm not sure how it will appear.
该Boundcolumn
属性不能更改为多个值。您可以尝试VbTab
在文本字段中用作分隔符,但我不确定它会如何显示。
Edit:
编辑:
Don't forget the default values. I think your Text field should show both columns beforethe user clicked on the list the first time, too.
不要忘记默认值。我认为您的 Text 字段也应该在用户第一次单击列表之前显示两列。
回答by David A Gibson
You can set a combobox text field to use data from multiple columns but you may need to write some code to do it.
您可以设置组合框文本字段以使用来自多列的数据,但您可能需要编写一些代码来执行此操作。
Try http://www.contextures.com/Excel-VBA-ComboBox-Lists.html