Visual Basic: Make a master-detail formset synchronize data edits

Platform:Visual Basic
Task:Make a master-detail formset synchronize data edits
Discussion:
Master-detail forms are common. Sometimes you launch the detail form, make edits and save the edits but the edits don't cascade back to the master form. You would think that if they are on the same TableAdapter and BindingSource the changes would cascade, but they don't. You need to force the master form's
Example:
    Private Sub SaveDataset()
        Try
            'save this detail form's edits
            Me.Validate()
            Me.TblSurveysBindingSource.EndEdit()
            Me.TblSurveysTableAdapter.Update(Me.SheepMonitoringDataSet)
            SheepMonitoringDataSet.AcceptChanges()

            'now cascade the changes back to the master form's binding source so the edits show in the datagridview
            frmMain.TblSurveysBindingSource.DataSource = SheepMonitoringDataSet.tblSurveys
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
Back to Index