Click to See Complete Forum and Search --> : [RESOLVED] Combo box binding to different table


gmcconville
November 22nd, 2011, 12:39 AM
Hey, I have searched for ages on this but cannot get it working.

I have two tables, one called Fields and another called Sections.

There is a relationship between the two table for a field called section.

I have a binding navigator on the form that is used to cycle through the different records in Fields.

I have a bunch of text boxes that properly display the information of the Fields correctly

I also have a combo box that I cannot get working, I need it to display the items on from the Sections table.

I am trying to code everything, so no wizards used.

This is what I have been trying so far



BSource = new BindingSource();
BSource.DataSource = DbDataSet.Tables["Fields"];
Navigator.BindingSource = BSource;

BSource2 = new BindingSource();
BSource2.DataSource = DbDataSet.Tables["Sections"];

// CbSections is the combobox
CbSections.DataSource = BSource2;
CbSections.DataBindings.Add("Text", BSource, "Section");
CbSections.DisplayMember = "Sections.Section";


Also. Can sombody please recommend a good ADO.NET book.

I am looking at buying Sams Teach Youself ADO.NET in 21 days, however it is expensive and I don't want to get it only to find it is not any good.

Thanks for all help.

gmcconville
November 28th, 2011, 02:59 AM
WOOOHOOOO!!!!!!

After two weeks of researching this I figured it out.

I use one binding source for all controls, and I needed to add a value member

BSource = new BindingSource();
BSource.DataSource = DbDataSet.Tables["Fields"];
Navigator.BindingSource = BSource;
TbProductType.DataBindings.Add("Text", BSource, "ProductType");

CbSections.DataSource = DbDataSet;
CbSections.DisplayMember = "Sections.Section";
CbSections.ValueMember = "Sections.key";
CbSections.DataBindings.Add("SelectedValue", BSource, "Section");

TbField01.DataBindings.Add("Text", BSource, "Field01");