|
-
November 22nd, 2011, 01:39 AM
#1
[RESOLVED] Combo box binding to different table
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
Code:
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.
-
November 28th, 2011, 03:59 AM
#2
Re: Combo box binding to different table
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
Code:
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");
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|