I have a master detail relationship where the master is displayed in a Datagridview and the detail in a multiline TextBox.
The data binding is set up with the foreign key relation as a Datasource for the Bindingsource for the detail, so it updates when you scroll trough the master table.
When a row is added in the master table, a row is not automatically inserted for the detail table.
I created a little example with the pubs sample database, where the publisher table is the master and the pub_info is the detail. When the Textbox is entered, I create the row myself and add it to the dataset like in the following example.
private void pr_infoTextBox_Enter(object sender, EventArgs e)
{
if (pub_infoBindingSource.Count == 0){
pubsDataSet.pub_infoRow row = pubsDataSet.pub_info.Newpub_infoRow();
row.pub_id = ((publishersBindingSource.Current as DataRowView).Row as pubsDataSet.publishersRow).pub_id;
row.logo = null;
pubsDataSet.pub_info.Addpub_infoRow(row);
pub_infoBindingSource.Position = pubsDataSet.pub_info.Rows.IndexOf(row);
}
}
It seems to work, but I was wondering if there is a more elegant solution for the problem.
Thank you
Torsten

Master/Detail relation where Detail is a TextBox