Resolved Bindingsource and Combo box

CoachBarker

Well-known member
Joined
Jul 26, 2007
Messages
133
Programming Experience
1-3
OK it has been awhile since I did this, I have a binding source, a Data Table, a Table Adapter and a combo box. Can someone help me with the steps to fill a combo box using these parts? When I fget done I am Showing System.Data....

Example.JPG

Binding Source = bsServices
Data Table = tblService
Table Adapter = tblServiceTableAdapter

VB.NET:
Private Sub frmComboBoxes_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'TestDataBaseDataSet.tblService' table. You can move, or remove it, as needed.
    Me.TblServiceTableAdapter.Fill(Me.TestDataBaseDataSet.tblService)

    'Bind the combobox control to the binding source              
    Me.cboServices.DisplayMember = "service"
    Me.cboServices.ValueMember = "serviceID"
    Me.cboServices.DataSource = Me.bsServices
End Sub
 
Last edited:
Why is this being bound to the binding source instead of directly to your table?

VB.NET:
    cboServices.DataSource = tblService
    cboServices.DisplayMember = "service"
    cboServices.ValueMember = "serviceID"

Note: just to point out that ServiceId is spelled differently in your photo
 
Here's an example using the Contact Table from the AdventureWorks database.

VB.NET:
		Me.ContactTableAdapter.Fill(Me.AdventureWorksDataSet.Contact)

		Dim ContactBindingSource As New BindingSource
		ContactBindingSource.DataSource = AdventureWorksDataSet
		ContactBindingSource.DataMember = "Contact"

		Me.ComboBox1.DataSource = ContactBindingSource
		Me.ComboBox1.DisplayMember = "FirstName"
		Me.ComboBox1.ValueMember = "ContactID"

Watch this video to about the 2:00 mark. She shows how you can have the designer set up everything for you automatically.

Visual Basic How Do I Forms Over Data 6
 
Tom, yeah that was a typo, I threw this together after work last night as a quick example.

MattP, I don't have adventure works, I have Northwinds, what does the "Contact" represent. Ah ok that would be "tblService" in my case. As simple as that it works.
 
Back
Top