Groups | Blog | Home
all groups > dotnet windows forms > june 2007 >

dotnet windows forms : Selecting a value in a bound combobox?


Magnus Bergh
6/27/2007 7:34:22 PM
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.

Paul Emery
6/28/2007 6:00:01 PM
don't you have to have a line like
customerBindingSource.endedit()
to "apply pending changes to the underlying datasource" ?
--
Paul Emery
Data Base and Ecommerce Consultant
Michigan


[quoted text, click to view]
AddThis Social Bookmark Button