setting a winforms combobox datasource at runtime

A

Ariel Gimenez

Hi i want to know how to do this:

i have a combobox in my app that is allready binded to a datatable and
has it properties valuemember and displaymember
now i want at runtime to assign to it another table...

this is the code im ussing in order to assign the new datasource but it
throwns an exception : unable to bind to a new valuemember

With Me.cboPayers
.DataBindings.Clear()
.DataSource = Nothing
.DataSource = payers.GetTable
.DisplayMember = "Descrip"
.ValueMember = "idPayee" 'here is where fails !!!
End With

thanks in advance
 
K

Ken Tucker [MVP]

Hi,

I have no problem changing the value member this way.

With ComboBox1

..DataSource = ds.Tables("Employee")

..DisplayMember = "LastName"

..ValueMember = "FirstName"

End With



With ComboBox1

..DataSource = ds.Tables("Orders")

..DisplayMember = "OrderID"

..ValueMember = "OrderDate"

End With



Ken

---------------------------

"Ariel Gimenez" <arielgimenez__arroba__hotmail.com> wrote in message
Hi i want to know how to do this:

i have a combobox in my app that is allready binded to a datatable and
has it properties valuemember and displaymember
now i want at runtime to assign to it another table...

this is the code im ussing in order to assign the new datasource but it
throwns an exception : unable to bind to a new valuemember

With Me.cboPayers
.DataBindings.Clear()
.DataSource = Nothing
.DataSource = payers.GetTable
.DisplayMember = "Descrip"
.ValueMember = "idPayee" 'here is where fails !!!
End With

thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top