Index: Core/Common/src/Core.Common.Controls/DataGrid/DataGridViewControl.cs =================================================================== diff -u -rb6d6acf62adcb4b23c4c5f6724fbd0091585bbb3 -rd533e8f7aa9448a0edd2c7cb40772549c66aff56 --- Core/Common/src/Core.Common.Controls/DataGrid/DataGridViewControl.cs (.../DataGridViewControl.cs) (revision b6d6acf62adcb4b23c4c5f6724fbd0091585bbb3) +++ Core/Common/src/Core.Common.Controls/DataGrid/DataGridViewControl.cs (.../DataGridViewControl.cs) (revision d533e8f7aa9448a0edd2c7cb40772549c66aff56) @@ -33,8 +33,6 @@ /// public partial class DataGridViewControl : UserControl { - private event EventHandler RowChanged; - /// /// Event handler that fires only when a new cell in a /// row different from the previously selected row is @@ -54,6 +52,9 @@ } } + /// + /// Occurs when the property changes. + /// public event EventHandler CurrentCellChanged { add @@ -66,6 +67,9 @@ } } + /// + /// Occurs when the contents of a cell need to be formatted for display. + /// public event DataGridViewCellFormattingEventHandler CellFormatting { add @@ -78,6 +82,9 @@ } } + /// + /// Occurs when the value of a cell changes. + /// public event DataGridViewCellEventHandler CellValueChanged { add @@ -90,6 +97,8 @@ } } + private event EventHandler RowChanged; + /// /// Creates a new instance of . /// @@ -177,12 +186,6 @@ } /// - /// Integer containing the index of the previously selected - /// row. - /// - private int LastSelectedRow { get; set; } - - /// /// Clears the current cell and resets the last selected row. /// public void ClearCurrentCell() @@ -432,6 +435,12 @@ base.OnLoad(e); } + /// + /// Integer containing the index of the previously selected + /// row. + /// + private int LastSelectedRow { get; set; } + #region Styling /// @@ -492,6 +501,7 @@ #endregion #region Event handling + private void DataGridViewOnCurrentCellChanged(object o, EventArgs eventArgs) { if (RowChanged == null) Index: Core/Common/test/Core.Common.Controls.Test/DataGrid/DataGridViewControlTest.cs =================================================================== diff -u -rb6d6acf62adcb4b23c4c5f6724fbd0091585bbb3 -rd533e8f7aa9448a0edd2c7cb40772549c66aff56 --- Core/Common/test/Core.Common.Controls.Test/DataGrid/DataGridViewControlTest.cs (.../DataGridViewControlTest.cs) (revision b6d6acf62adcb4b23c4c5f6724fbd0091585bbb3) +++ Core/Common/test/Core.Common.Controls.Test/DataGrid/DataGridViewControlTest.cs (.../DataGridViewControlTest.cs) (revision d533e8f7aa9448a0edd2c7cb40772549c66aff56) @@ -1053,7 +1053,7 @@ } [Test] - public void ClearCurrentCell_Always_SetsCurrentCellToNullAndResetsLastSelectedRow() + public void ClearCurrentCell_Always_SetsCurrentCellToNullAndAllowsNewEventToFire() { // Setup using (var form = new Form()) @@ -1071,6 +1071,8 @@ }); dataGridView.CurrentCell = control.GetCell(0, 0); + var counter = 0; + control.CurrentRowChanged += (sender, args) => counter++; // Precondition Assert.IsNotNull(dataGridView.CurrentCell); @@ -1079,8 +1081,11 @@ control.ClearCurrentCell(); // Assert + Assert.AreEqual(1, counter); Assert.IsNull(dataGridView.CurrentCell); - //Assert.AreEqual(-1, control.LastSelectedRow); + + control.SetCurrentCell(control.GetCell(0, 0)); + Assert.AreEqual(2, counter); } } @@ -1307,7 +1312,7 @@ #region Event handling [Test] - public void AddCellFormattingHandler_Always_AddsEventHandler() + public void CellFormatting_HandlerAdded_AddsEventHandler() { // Setup using (var form = new Form()) @@ -1340,7 +1345,7 @@ } [Test] - public void RemoveCellFormattingHandler_Always_RemovesEventHandler() + public void CellFormatting_HandlerRemoved_RemovesEventHandler() { // Setup using (var form = new Form()) @@ -1377,7 +1382,7 @@ } [Test] - public void AddCurrentRowChangedHandler_Always_AddsEventHandler() + public void CurrentRowChanged_HandlerAdded_AddsEventHandler() { // Setup using (var form = new Form()) @@ -1390,7 +1395,7 @@ var handlerExecuted = false; // Call - control.CurrentRowChanged += ((sender, args) => handlerExecuted = true); + control.CurrentRowChanged += (sender, args) => handlerExecuted = true; // Assert gridTester.FireEvent("CurrentCellChanged", new EventArgs()); @@ -1399,7 +1404,7 @@ } [Test] - public void RemoveCurrentRowChangedHandler_Always_RemovesEventHandler() + public void CurrentRowChanged_HandlerRemoved_RemovesEventHandler() { // Setup using (var form = new Form()) @@ -1412,15 +1417,15 @@ var counter = 0; EventHandler eventHandler = (sender, args) => counter++; - control.CurrentRowChanged += (eventHandler); + control.CurrentRowChanged += eventHandler; // Precondition Assert.AreEqual(0, counter); gridTester.FireEvent("CurrentCellChanged", new EventArgs()); Assert.AreEqual(1, counter); // Call - control.CurrentRowChanged -= (eventHandler); + control.CurrentRowChanged -= eventHandler; // Assert gridTester.FireEvent("CurrentCellChanged", new EventArgs()); @@ -1429,7 +1434,7 @@ } [Test] - public void AddCurrentCellChangedHandler_Always_AddsEventHandler() + public void CurrentCellChanged_HandlerAdded_AddsEventHandler() { // Setup using (var form = new Form()) @@ -1452,7 +1457,7 @@ } [Test] - public void RemoveCurrentCellChangedHandler_Always_RemovesEventHandler() + public void CurrentCellChanged_HandlerRemoved_RemovesEventHandler() { // Setup using (var form = new Form()) @@ -1482,7 +1487,7 @@ } [Test] - public void AddCellValueChangedHandler_Always_AddsEventHandler() + public void CellValueChanged_HandlerAdded_AddsEventHandler() { // Setup using (var form = new Form()) @@ -1516,7 +1521,7 @@ } [Test] - public void RemoveCellValueChangedHandler_Always_RemovesEventHandler() + public void CellValueChanged_HandlerRemoved_RemovesEventHandler() { // Setup using (var form = new Form()) @@ -1769,7 +1774,7 @@ } [Test] - public void CurrentRowChangedHandler_SelectedCellInNewRow_ExecuteEventHandler() + public void CurrentRowChanged_SelectedCellInNewRow_ExecuteEventHandler() { // Setup using (var form = new Form()) @@ -1788,7 +1793,7 @@ control.SetCurrentCell(control.GetCell(0, 0)); var handlerExecuted = false; - control.CurrentRowChanged += ((sender, args) => handlerExecuted = true); + control.CurrentRowChanged += (sender, args) => handlerExecuted = true; // Call control.SetCurrentCell(control.GetCell(1, 0)); @@ -1799,7 +1804,7 @@ } [Test] - public void CurrentRowChangedHandler_FirstSelection_ExecuteEventHandler() + public void CurrentRowChanged_FirstSelection_ExecuteEventHandler() { // Setup using (var form = new Form()) @@ -1819,7 +1824,7 @@ }); var handlerExecuted = false; - control.CurrentRowChanged += ((sender, args) => handlerExecuted = true); + control.CurrentRowChanged += (sender, args) => handlerExecuted = true; // Call control.SetCurrentCell(control.GetCell(0, 0)); @@ -1831,7 +1836,7 @@ } [Test] - public void CurrentRowChangedHandler_SelectCellInSameRow_SkipEventHandler() + public void CurrentRowChanged_SelectCellInSameRow_SkipEventHandler() { // Setup using (var form = new Form()) @@ -1850,7 +1855,7 @@ }); var handlerExecuted = false; - control.CurrentRowChanged += ((sender, args) => handlerExecuted = true); + control.CurrentRowChanged += (sender, args) => handlerExecuted = true; // Precondition control.SetCurrentCell(control.GetCell(0, 0)); @@ -1868,7 +1873,7 @@ } [Test] - public void CurrentRowChangedHandler_SetCurrentCellToNull_ResetsLastSelectedRow() + public void CurrentRowChanged_SetCurrentCellToNull_FiresRowChangedEventAndAllowsNewEventToFire() { // Setup using (var form = new Form()) @@ -1885,25 +1890,25 @@ new TestDataGridViewRow(new RoundedDouble(0, 2.5)) }); - control.CurrentRowChanged += ((sender, args) => {}); - - // Precondition + var counter = 0; + control.CurrentRowChanged += (sender, args) => counter++; control.SetCurrentCell(control.GetCell(0, 0)); gridTester.FireEvent("CurrentCellChanged", EventArgs.Empty); - //Assert.AreEqual(0, control.LastSelectedRow); // Call control.SetCurrentCell(null); // Assert - // Assert.AreEqual(-1, control.LastSelectedRow); + Assert.AreEqual(2, counter); + control.SetCurrentCell(control.GetCell(0, 0)); + Assert.AreEqual(3, counter); } } [Test] [TestCase(true)] [TestCase(false)] - public void CurrentRowChangedHandler_SetHandlerToNullOrNotSet_DoesNothing(bool setToNull) + public void CurrentRowChanged_SetHandlerToNullOrNotSet_DoesNothing(bool setToNull) { // Setup using (var form = new Form()) Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/IllustrationPointsControlTest.cs =================================================================== diff -u -redb617ef7d51ddd52ed0b0095e679106925a837c -rd533e8f7aa9448a0edd2c7cb40772549c66aff56 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/IllustrationPointsControlTest.cs (.../IllustrationPointsControlTest.cs) (revision edb617ef7d51ddd52ed0b0095e679106925a837c) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/IllustrationPointsControlTest.cs (.../IllustrationPointsControlTest.cs) (revision d533e8f7aa9448a0edd2c7cb40772549c66aff56) @@ -87,7 +87,7 @@ } [Test] - public void Data_ValueSet_ResetsLastSelectedRow() + public void GivenFullyConfiguredControl_WhenDataIsResetAndCellInSameRowSelected_ThenRowChangedFired() { // Setup using (var form = new Form()) @@ -102,28 +102,22 @@ "SSE", "Regular", Enumerable.Empty(), - (RoundedDouble) 3.14), - new IllustrationPointControlItem(new TestTopLevelIllustrationPoint(), - "NE", - "Regular", - Enumerable.Empty(), - (RoundedDouble) 5.2) + (RoundedDouble) 3.14) }; - control.Data = data; - var selectionChangedCount = 0; - control.SelectionChanged += (sender, args) => selectionChangedCount++; - DataGridViewControl dataGridView = ControlTestHelper.GetDataGridViewControl(form, "illustrationPointsDataGridViewControl"); + var selectionChangedCount = 0; + dataGridView.CurrentRowChanged += (sender, args) => selectionChangedCount++; dataGridView.SetCurrentCell(dataGridView.Rows[0].Cells[0]); // Call - control.Data = data; + control.Data = null; + control.Data = data; // Updating data fires event 2 times, then resets to allow next cell change to fire again dataGridView.SetCurrentCell(dataGridView.Rows[0].Cells[2]); // Assert - Assert.AreEqual(1, selectionChangedCount); + Assert.AreEqual(4, selectionChangedCount); } }