Parent and Child new row on windows forms details

Problem is that
Me.ParentBindingSource.AddNew
Me.ChildBindingSource.AddNew

then when saving:
Me.ParentBindingSource.EndEdit
will destroy child row.

My workaround is:
Store a variable stating is NewRow and/or child row data IsMissing
Then on SaveData use:
If NewRow OrElse IsChildRowMissing Then
  StoreData
End If
Me.ParentBindingSource.EndEdit
If NewRow OrElse IsChildRowMissing Then
  Using taP as New dsTableAdapters.ParentTableAdapter
     taP.Update(ds)
  End Using
  DisplayStoredData – which includes re-adding child row
End If
Continue with normal save

This link describes problem but is not much help to solution:
http://www.vbdotnetforums.com/database-general-discussion/13058-calling-endedit-causes-datarelations-fail.html

Leave a comment