Can a combobox have more than one column in its part of a text field?

I have a two-column list in my combobox, and when I select one of the elements in it using the drop-down list, it saves (what I see in the text box in the combo box) only the value that I selected (the one which is in the right or left column according to the boundcolumn)

My question is: is there a way to save (or imagine - this is my goal) in part of the text field in the combo box, are both columns from the same row selected?

For example: [column1] Daniel [column2] Smith. And in the text box I want: Daniel Smith (and not just Daniel, or Smith, they themselves).

+2
vba combobox
source share
2 answers

You can set the combobox text box to use data from multiple columns, but you may need to write code to do this.

Try http://www.contextures.com/Excel-VBA-ComboBox-Lists.html

0
source share

What you describe is theoretically possible, but with limitations.

Even if you did not ask for it, here is my idea :

As described here , you can change your ComboBox text without changing its value . This allows you to "store" the base value while displaying both columns in one.

Listen to 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 just a basic example.) You cannot test it right now, but in .Net you can use CType to explicitly convert the sender argument to a ComboBox variable and access it that way.

The Boundcolumn property cannot be changed to multiple values. You can try using VbTab as a delimiter in the text box, but I'm not sure how it will appear.

Edit:

Do not forget the default values. I think your text box should show both the columns before and the user by clicking on the list for the first time.

0
source share

All Articles