Selecting a value in a bound combobox?

  • Thread starter Thread starter Magnus Bergh
  • Start date Start date
M

Magnus Bergh

I thought this was easy, just to SelectedValue in code for example
Combobox1.SelectedValue= "ABC". Looks on screen like it works and the
correct value shows in the combobox but the underlying datasource is not
updated.

It is like the usual order entry example where you have a combox
displaying customer names and selectedvalue bound to the order's
customerid and valuemember to customer id of customer bindingsource. So
what I want to do is to select the correct customer in the combobox
using the customer id.

What I did was instead to use the bindingsource.find method and set
position in bindingsource which seems to work fine.

For example:

index=CustomerBindingSource.Find("CustomerId", customerid)
if index <> -1 then CustomerBindingSource.Position= index

where customerid is the id of the customer I want to find.

Is this the correct method to do this?
 
don't you have to have a line like
customerBindingSource.endedit()
to "apply pending changes to the underlying datasource" ?
 
Back
Top