CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2010
    Posts
    13

    [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.

  2. #2
    Join Date
    Feb 2010
    Posts
    13

    Talking 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
  •  





Click Here to Expand Forum to Full Width

Featured