Okay, generally, you have one dataset with both of the
tables in it. Then you need to set up a binding source,
and set the data member and data source
of your controls accordingly. Here's an example.
I don't know how you are creating your dataset. I am
going to assume you created it with the DataSetDesigner?
Or are you creating it on your own? If you're creating
it on your own, that's a different ball of wax, because
you have to handle the relations on your own.
I have a dataset that has two tables: Customers and Orders.
(This runs against Northwind, so if you have that
installed, you can try this out.)
I set up a strongly-typed dataset using the Data Set
Designer with both of those tables in it, and there is
a field called CustomerID in the Orders table that links
to the CustomerID table in Customers. So Orders have a
Customer as a parent. The data relation between
the customer and the orders is defined as FK_Orders_Customers.
This is in Form_Load:
'First, populate the dataset.
Dim nwData As CustomersDataSet = CustomersDataSet.GetCustomers()
'Set the data source for the binding source to the dataset.
CustomersBindingSource.DataSource = nwData
'Add this so it knows which table to use .
CustomersBindingSource.DataMember = "Customers"
'Set the data source for the grid to the customers binding source.
CustomersDataGridView.DataSource = CustomersBindingSource
'Add the binding for the child; set its binding source to the same
' one as the parent.
Customers_OrdersBindingSource.DataSource = CustomersBindingSource
'Set the datamember to the foreign key joining the two tables.
' You can see this on your CustomersDataSet diagram.
Customers_OrdersBindingSource.DataMember = "FK_Orders_Customers"
'Set the data source on the child grid to points at its binding source.
OrdersDataGridView.DataSource = Customers_OrdersBindingSource
AddTextBoxDataBindings()
AddComboBoxDataBindings()
Here are the routines that bind the textboxes and combo box
in case you want them.
Private Sub AddTextBoxDataBindings()
'Bind each text box to the appropriate field in the
' CustomersBindingSource
CustomerIDTextBox.DataBindings.Add("Text", _
CustomersBindingSource, "CustomerID")
ContactNameTextBox.DataBindings.Add("Text", _
CustomersBindingSource, "ContactName")
CompanyNameTextBox.DataBindings.Add("Text", _
CustomersBindingSource, "CompanyName")
ContactPhoneTextBox.DataBindings.Add("Text", _
CustomersBindingSource, "Phone")
End Sub
Private Sub AddComboBoxDataBindings()
ContactsComboBox.DataSource = CustomersBindingSource
ContactsComboBox.DisplayMember = "ContactName"
ContactsComboBox.ValueMember = "CustomerID"
End Sub
Hope that provides enough info. This information
came out of Brian Noyes's book on Data Binding.
If you want to do updates, let them change the data in the
grid, then call the Update method on your table adapter:
CustomersTableAdapter.Update(ds)
I think that should work. Good luck.
Robin S.