Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/AssemblyResultTotalView.cs =================================================================== diff -u -r8e42df9f0d1e647da23c12d02932efe41691a15c -r933d13f37606dd02f49148d8f1c4bb556b1dfbdf --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/AssemblyResultTotalView.cs (.../AssemblyResultTotalView.cs) (revision 8e42df9f0d1e647da23c12d02932efe41691a15c) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/AssemblyResultTotalView.cs (.../AssemblyResultTotalView.cs) (revision 933d13f37606dd02f49148d8f1c4bb556b1dfbdf) @@ -53,9 +53,12 @@ /// public partial class AssemblyResultTotalView : UserControl, IView { + private readonly Observer assessmentSectionObserver; private readonly Observer assessmentSectionResultObserver; private IEnumerable assemblyResultRows; + private bool updateDataSource; + /// /// Creates a new instance of . /// @@ -73,6 +76,15 @@ InitializeComponent(); + assessmentSectionObserver = new Observer(() => + { + updateDataSource = true; + EnableRefreshButton(); + }) + { + Observable = assessmentSection + }; + assessmentSectionResultObserver = new Observer(EnableRefreshButton) { Observable = new AssessmentSectionResultObserver(assessmentSection) @@ -98,11 +110,10 @@ protected override void Dispose(bool disposing) { - dataGridViewControl.CellFormatting -= HandleCellStyling; - if (disposing) { components?.Dispose(); + assessmentSectionObserver.Dispose(); assessmentSectionResultObserver.Dispose(); } @@ -141,10 +152,10 @@ Resources.AssemblyResultTotalView_Probability_DisplayName, true); - InitializeRows(); + SetDataSource(); } - private void InitializeRows() + private void SetDataSource() { assemblyResultRows = new List { @@ -169,15 +180,24 @@ }; dataGridViewControl.SetDataSource(assemblyResultRows); + updateDataSource = false; } private void RefreshAssemblyResults_Click(object sender, EventArgs e) { refreshAssemblyResultsButton.Enabled = false; warningProvider.SetError(refreshAssemblyResultsButton, string.Empty); - assemblyResultRows.ForEachElementDo(row => row.Update()); - dataGridViewControl.RefreshDataGridView(); + if (updateDataSource) + { + SetDataSource(); + } + else + { + assemblyResultRows.ForEachElementDo(row => row.Update()); + dataGridViewControl.RefreshDataGridView(); + } + UpdateAssemblyResultControls(); } Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/AssemblyResultTotalViewTest.cs =================================================================== diff -u -r03a42f53227ba94fae59ac8a103861e201138398 -r933d13f37606dd02f49148d8f1c4bb556b1dfbdf --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/AssemblyResultTotalViewTest.cs (.../AssemblyResultTotalViewTest.cs) (revision 03a42f53227ba94fae59ac8a103861e201138398) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/AssemblyResultTotalViewTest.cs (.../AssemblyResultTotalViewTest.cs) (revision 933d13f37606dd02f49148d8f1c4bb556b1dfbdf) @@ -344,6 +344,7 @@ var invalidated = false; DataGridView dataGridView = GetDataGridView(); dataGridView.Invalidated += (sender, args) => invalidated = true; + object dataSource = dataGridView.DataSource; // Precondition Assert.IsFalse(invalidated); @@ -361,7 +362,8 @@ buttonTester.Click(); - // Then + // Then + Assert.AreSame(dataSource, dataGridView.DataSource); Assert.IsTrue(invalidated); AssertFailureMechanismRows(view.AssessmentSection, newAssemblyResult, newCategoryGroup, rows); } @@ -501,6 +503,29 @@ } } + [Test] + [SetCulture("nl-NL")] + public void GivenAssessmentSectionObserversNotified_WhenRefreshingAssemblyResults_ThenDataGridViewDataSourceUpdated() + { + // Given + using (new AssemblyToolCalculatorFactoryConfig()) + using (AssemblyResultTotalView view = ShowAssemblyResultTotalView()) + { + ButtonTester buttonTester = GetRefreshAssemblyResultButtonTester(); + buttonTester.Properties.Enabled = true; + + DataGridView dataGridView = GetDataGridView(); + object dataSource = dataGridView.DataSource; + + // When + view.AssessmentSection.NotifyObservers(); + buttonTester.Click(); + + // Then + Assert.AreNotSame(dataSource, dataGridView.DataSource); + } + } + #region View test helpers private AssemblyResultTotalView ShowAssemblyResultTotalView() @@ -534,7 +559,7 @@ private static FailureMechanismAssemblyControl GetFailureMechanismAssemblyControl() { - return (FailureMechanismAssemblyControl)new ControlTester(failureMechanismsWithProbabilityControlName).TheObject; + return (FailureMechanismAssemblyControl) new ControlTester(failureMechanismsWithProbabilityControlName).TheObject; } private static BorderedLabel GetGroupLabel(AssemblyResultControl control)