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

前端 未结 2 1431
夕颜
夕颜 2021-01-22 22:05

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 va

2条回答
  •  清酒与你
    2021-01-22 22:34

    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.

提交回复
热议问题