2

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)

Michel de Ruiter
  • 7,131
  • 5
  • 49
  • 74
eagleye
  • 582
  • 1
  • 8
  • 12
  • Yes, there is a way to store it. Keep in mind, that your program has to know how to split the 2 cols up again (if you want to identifiy your dataset). Add a EventHandler for changed index and load the 2nd column in your text field. – Clijsters May 06 '16 at 07:17

2 Answers2

1

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.

Community
  • 1
  • 1
Clijsters
  • 4,031
  • 1
  • 27
  • 37
-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

David A Gibson
  • 2,013
  • 5
  • 35
  • 60
  • 1
    That's not what I meant. What I meant was to simply SHOW the two columns in the text area of the combobox BEFORE clicking on it. I wan't to see the two columns in the texbox area of the combobox and NOT only the drop down area. you know what I mean? -just to present the two columns of the active item in the textbox area. – eagleye Aug 24 '11 at 10:02