0
votes

I bind a datatable to the combobox.DataSource on load. I then give the combobox a DisplayMember and a ValueMember (2 different columns out of the datatable). In the SelectedIndexChanged of the combobox I would like to use the SelectedValue property of the combobox, just to test I MsgBox(combobox.SelectedValue) and I get "Argument 'Prompt' cannot be converted to type 'String'." Why isn't it displaying the value? :(

OnLoad
    cbCISoftware.DataSource = dbMaps.Tables("maps")
    cbCISoftware.ValueMember = "id"
    cbCISoftware.DisplayMember = "name"

SelectedIndexChanged of cbCISoftware
    MsgBox(cbCISoftware.SelectedValue)

SelectedValue.ToString outputs
    System.Data.DataRowView
2
Can you add your databinding code and the selectedindexchanged code so we can double-check?competent_tech
Added the code! (also the DisplayMember shows fine on the form)Theveloper

2 Answers

1
votes

I believe the issue is that you need to bind the table's DefaultView:

cbCISoftware.DataSource = dbMaps.Tables("maps").DefaultView
0
votes

First of all you have to be sure to have selected DropDownList as DropDownStyle for the Combobox and that the binding is working.

Then you have to replace MsgBox(cbCISoftware.SelectedValue) with MsgBox(cbCISoftware.SelectedValue.ToString)

Otherwise to obtain the result, MsgBox(cbCISoftware.Text) will work, but it not probably what you are looking for :-)

I can provide you with complete code to do the binding if you need it.