luis reis

luis reis

  • NA
  • 134
  • 0

VS2005 Master-Detail - using auxilary grid prevents Detail records saving.

May 29 2009 2:38 PM

As a beginner I used VS2005 IDE to design a Master-Detail Form with databinding navigator. Master Table  is an Outlook Message header and Detail Table holds information about attachments.
I use in the same Form a textbox and an auxiliary datagrid  where the name and size of attachments are writen as my code shows it. This datagridview  is important because I want to select attachments and not all of them. When I click,  it adds at Detail Datagrid as second  column the Line Number ( it belongs to composite primary key ) and on the 4 column the path of the attachment.
The problem I have is: when the Detail DataGridview is filled ( after clicking the attachments I want ) I make the Save on the Navigator and only Master record is saved ( no detail record is saved ) . After some "googling" I understand that this can be linked with BeginEdit in Detail Table but ( as a beginner ) I cannot solve this issue even after reading a lot of commnts.
Any help is appreciated ( adding the missing code to my code ).
  
private
void cabMailBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.detMailBindingSource.EndEdit();
this.cabMailBindingSource.EndEdit();
this.cabMailTableAdapter.Update(this.controllerDataSet.CabMail);
this.detMailTableAdapter.Update(this.controllerDataSet.DetMail);
}
 
 
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

            //auxiliary Grid.
            ++l;
            textBox1.Text = dataGridView1.CurrentCell.Value.ToString();
            System.Diagnostics.Process.Start("mspaint.exe", textBox1.Text);
            DataRow dr = dtg1.NewRow();
            dr[0] = codTextBox.Text;
            dr[1] = l;
            dr[3] = textBox1.Text;
            dtg1.Rows.Add(dr);
            //detMailGridView.BeginEdit() - ???????????
            //fill detail grid
            detMailDataGridView.DataSource = dtg1;
            //( after this instruction I click Save 
        }