Groups | Blog | Home
all groups > dotnet datatools > may 2006 >

dotnet datatools : databinding combobox



Frank
5/27/2006 2:40:02 PM
Hi, I'm trying to build my first vb2005 dataapp but I'm somewhat lost here. I
have a database table displayed in a grid. This table has a field called
countryid which is linked to another table with the actual countrynames. On
the same form I have a combobox which should be linked to both tables in
order to display the names. In VB6 this was done easily through .datafield,
..boundcolumn and listfield. How should I do this in vb2005?

Thanks,
Frank
Eric Moreau
5/28/2006 9:23:16 AM
It is much the same in 2005.

You need 2 BindingSource:
-BindingSource1 = The table that contains your linked field
-BindingSource2 = YourCountryNamesTable

You then need to set 4 properties of the ComboBox:
-DataSource (BindingSource2)
-DisplayMember (The ID field from BindingSource2)
-ValueMember (The field you want to display from BindingSource2)
-SelectedValue (The ID field from BindingSource1)

--


HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Concept S2i inc. (www.s2i.com)
http://emoreau.s2i.com/

[quoted text, click to view]

Ranko
6/2/2006 5:36:23 PM
[quoted text, click to view]

A little mistake here (swap DisplayMember and ValueMember):
-DisplayMember(The field you want to display from BindingSource2)
derrick ribilla
6/19/2006 10:48:43 AM
Here's a link to combobox databinding solution:

http://www.breakoutseason.com/derrick_ribilla/simple_combobox_databindin
g_windows_forms_binding_source_problem_solution.html



AddThis Social Bookmark Button