Can a combobox present more then one column on its textbox part?

自闭症网瘾萝莉.ら 提交于 2019-12-31 02:49:08

问题


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)

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)


回答1:


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




回答2:


What you describe is theoretically possible, but with restrictions.

Even when you didn't ask for that, here comes my idea:

Like described here you can change your ComboBox's text without changing its value. This allows you to 'store' the underlying value while displaying both columns in one.

Listen on the SelectedIndexChanged Event and change the text property as follows:

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.

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.

Edit:

Don't forget the default values. I think your Text field should show both columns before the user clicked on the list the first time, too.



来源:https://stackoverflow.com/questions/6867461/can-a-combobox-present-more-then-one-column-on-its-textbox-part

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!