simpledata2.zip
What this boils down to is this:
1) Load both Master and Details queries in a dataset.
// I am using the SQL server NorthWind database
this.dataAdapterMaster.Fill(this.dataSet, "Customers");
this.dataAdapterDetails.Fill(this.dataSet, "Orders");
2) Bind the master data grid to the Master dataset table.
// The master view
grid.DataSource = this.dataSet;
grid.DataMember = "Customers";
3) Create a relationship that describes how the two tables relate to each other. A primary key foriegn key relationship is defined by two attributes.
The primary key column in the master table
The foreign key coumn in the details table
The created relationship is added to the dataset.
this.dataSet.Relations.Add("CustomersToOrders",
dataSet.Tables["Customers"].Columns["CustomerID"],
dataSet.Tables["Orders"].Columns["CustomerID"]);
4) Set the data member for the details table to be the name of relationship that was added to the dataset.
// The name of the relation is to be used as the DataMember for the
// details view
details.DataSource = this.dataSet;
// use the relationship called "CustomersToOrders in the Customers table.
// Remember that we called the relationship "CustomersToOrders".
details.DataMember = "Customers.CustomersToOrders";
Contributed from George Shepherd's Windows Forms FAQ