I have a table, SampleData, that has a child table, Measurements. On my WinForm, frmMain, a single SampleData object is bound to the SampleDataBindingSource; the MeasurementsBindingSource has SampleDataBindingSource as its datasource and Measurements as its DataMember. A set of textboxes are bound to SampleDataBindingSource; a datagridview is bound to MeasurementsBindingSource.
For frmMain, I also have a presenter class, preMain, which contains a property, CurrentSample, of type SampleData. The SampleDataBindingSource.DataSource
is bound to the CurrentSample property of preMain.
When enough of the properties in Measurements have been assigned, it calculates the FiringFactor and, if the FiringFactor is not 1, it adds another Measurement item to the CurrentSample's Measurement entityset:
Partial Class Measurement
Private Sub UpdateFiringFactor()
Dim necessaryDataIsAvailable As Boolean = (Me.CrucibleMass IsNot Nothing And _
Me.CrucibleSampleFiredMass IsNot Nothing And _
Me.CrucibleSampleMass IsNot Nothing)
If necessaryDataIsAvailable Then
Me.FiringFactor = CDbl((Me.CrucibleSampleFiredMass - Me.CrucibleMass) / (Me.CrucibleSampleMass - Me.CrucibleMass))
If Me.FiringFactor <> 1 Then
Me.SampleData.AddNewMeasurement()
End If
End If
End Sub
Private Sub OnCrucibleMassChanged()
UpdateFiringFactor()
End Sub
Private Sub OnCrucibleSampleFiredMassChanged()
UpdateFiringFactor()
End Sub
Private Sub OnCrucibleSampleMassChanged()
UpdateFiringFactor()
End Sub
End Class
When I enter values for CrucibleMass, CrucibleSampleMass, and CrucibleSampleFiredMass in the datagridview, the UpdateFiringFactor method does run correctly and I eventually get another Measurement item added to CurrentSample's Measurements entityset. However, the datagridview does not show a new row and the MeasurementsBindingSource only has 1 record (but CurrentSample.Measurements.Count = 2
).
Why does the change in CurrentSample.Measurements
not propogate to MeasurementsBindingSource
? I have tried MeasurementsBindingSource.ResetBindings(False)
, MeasurementsDataGridView.Refresh
, SampleDataBindingSource.ResetBindings(False)
, but nothing seems to update MeasurementsBindingSource
or its datagridview.