Index: Core/Common/src/Core.Common.Controls/DataGrid/DataGridViewControl.cs =================================================================== diff -u -r5c08229e46f7bdab0ad1d754956f152c90ab3169 -r0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3 --- Core/Common/src/Core.Common.Controls/DataGrid/DataGridViewControl.cs (.../DataGridViewControl.cs) (revision 5c08229e46f7bdab0ad1d754956f152c90ab3169) +++ Core/Common/src/Core.Common.Controls/DataGrid/DataGridViewControl.cs (.../DataGridViewControl.cs) (revision 0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3) @@ -21,6 +21,7 @@ using System; using System.Windows.Forms; +using Core.Common.Controls.Properties; namespace Core.Common.Controls.DataGrid { @@ -96,12 +97,15 @@ private void SubscribeEvents() { - dataGridView.CurrentCellDirtyStateChanged += DataGridViewCurrentCellDirtyStateChanged; + dataGridView.CurrentCellDirtyStateChanged += DataGridViewOnCurrentCellDirtyStateChanged; + dataGridView.GotFocus += DataGridViewOnGotFocus; + dataGridView.CellValidating += DataGridViewOnCellValidating; + dataGridView.DataError += DataGridViewOnDataError; } #region Event handling - private void DataGridViewCurrentCellDirtyStateChanged(object sender, EventArgs e) + private void DataGridViewOnCurrentCellDirtyStateChanged(object sender, EventArgs e) { // Ensure checkbox values are directly committed DataGridViewColumn currentColumn = dataGridView.Columns[dataGridView.CurrentCell.ColumnIndex]; @@ -111,6 +115,36 @@ } } + private void DataGridViewOnGotFocus(object sender, EventArgs e) + { + if (dataGridView.CurrentCell != null) + { + dataGridView.BeginEdit(true); // Always start editing after setting the focus (otherwise data grid view cell dirty events are no longer fired when using the keyboard...) + } + } + + private void DataGridViewOnCellValidating(object sender, DataGridViewCellValidatingEventArgs e) + { + dataGridView.Rows[e.RowIndex].ErrorText = String.Empty; + + var cellEditValue = e.FormattedValue.ToString(); + if (string.IsNullOrWhiteSpace(cellEditValue)) + { + dataGridView.Rows[e.RowIndex].ErrorText = Resources.DataGridViewCellValidating_Text_may_not_be_empty; + } + } + + private void DataGridViewOnDataError(object sender, DataGridViewDataErrorEventArgs e) + { + e.ThrowException = false; + e.Cancel = true; + + if (string.IsNullOrWhiteSpace(dataGridView.Rows[e.RowIndex].ErrorText) && e.Exception != null) + { + dataGridView.Rows[e.RowIndex].ErrorText = e.Exception.Message; + } + } + #endregion } } \ No newline at end of file Index: Core/Common/src/Core.Common.Controls/Properties/Resources.Designer.cs =================================================================== diff -u -rb389b4d34dab98838a8c2f087b18cfdac544f01f -r0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3 --- Core/Common/src/Core.Common.Controls/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision b389b4d34dab98838a8c2f087b18cfdac544f01f) +++ Core/Common/src/Core.Common.Controls/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3) @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.42000 +// Runtime Version:4.0.30319.17929 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -71,6 +71,15 @@ } /// + /// Looks up a localized string similar to De tekst mag niet leeg zijn.. + /// + public static string DataGridViewCellValidating_Text_may_not_be_empty { + get { + return ResourceManager.GetString("DataGridViewCellValidating_Text_may_not_be_empty", resourceCulture); + } + } + + /// /// Looks up a localized string similar to <geen>. /// public static string DataGridViewComboBoxItemWrapper_DisplayName_None { Index: Core/Common/src/Core.Common.Controls/Properties/Resources.resx =================================================================== diff -u -rb389b4d34dab98838a8c2f087b18cfdac544f01f -r0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3 --- Core/Common/src/Core.Common.Controls/Properties/Resources.resx (.../Resources.resx) (revision b389b4d34dab98838a8c2f087b18cfdac544f01f) +++ Core/Common/src/Core.Common.Controls/Properties/Resources.resx (.../Resources.resx) (revision 0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3) @@ -124,4 +124,7 @@ <geen> + + De tekst mag niet leeg zijn. + \ No newline at end of file Index: Core/Common/test/Core.Common.Controls.Test/DataGrid/DataGridViewControlTest.cs =================================================================== diff -u -r5c08229e46f7bdab0ad1d754956f152c90ab3169 -r0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3 --- Core/Common/test/Core.Common.Controls.Test/DataGrid/DataGridViewControlTest.cs (.../DataGridViewControlTest.cs) (revision 5c08229e46f7bdab0ad1d754956f152c90ab3169) +++ Core/Common/test/Core.Common.Controls.Test/DataGrid/DataGridViewControlTest.cs (.../DataGridViewControlTest.cs) (revision 0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3) @@ -205,5 +205,102 @@ Assert.IsTrue((bool)dataGridViewCell.FormattedValue); } } + + [Test] + public void DataGridView_GotFocusCurrentCellSet_CellInEditMode() + { + // Setup + using (var form = new Form()) + { + var control = new DataGridViewControl(); + form.Controls.Add(control); + form.Show(); + + var gridTester = new ControlTester("dataGridView"); + var dataGridView = (DataGridView)gridTester.TheObject; + + // Make sure the cell is not in edit mode when setting the current cell. + dataGridView.EditMode = DataGridViewEditMode.EditProgrammatically; + + control.AddTextBoxColumn("Test property", "Test header"); + + dataGridView.DataSource = new[] { "" }; + + var dataGridViewCell = dataGridView.Rows[0].Cells[0]; + dataGridView.CurrentCell = dataGridViewCell; + + // Precondition + Assert.IsFalse(dataGridView.IsCurrentCellInEditMode); + + // Call + gridTester.FireEvent("GotFocus", EventArgs.Empty); + + // Assert + Assert.IsTrue(dataGridView.IsCurrentCellInEditMode); + } + } + + [Test] + public void DataGridView_GotFocusCurrentCellNull_CellNotInEditMode() + { + // Setup + using (var form = new Form()) + { + var control = new DataGridViewControl(); + form.Controls.Add(control); + form.Show(); + + var gridTester = new ControlTester("dataGridView"); + var dataGridView = (DataGridView)gridTester.TheObject; + + // Make sure the cell is not in edit mode when setting the current cell. + dataGridView.EditMode = DataGridViewEditMode.EditProgrammatically; + + control.AddTextBoxColumn("Test property", "Test header"); + + dataGridView.DataSource = new[] { "" }; + dataGridView.CurrentCell = null; + + // Precondition + Assert.IsFalse(dataGridView.IsCurrentCellInEditMode); + + // Call + gridTester.FireEvent("GotFocus", EventArgs.Empty); + + // Assert + Assert.IsFalse(dataGridView.IsCurrentCellInEditMode); + } + } + + [Test] + public void DataGridView_CellValidatingValueValid_DoesNotShowErrorToolTip() + { + // Setup + using (var form = new Form()) + { + var control = new DataGridViewControl(); + form.Controls.Add(control); + form.Show(); + + var gridTester = new ControlTester("dataGridView"); + var dataGridView = (DataGridView)gridTester.TheObject; + + // Make sure the cell is not in edit mode when setting the current cell. + dataGridView.EditMode = DataGridViewEditMode.EditProgrammatically; + + control.AddTextBoxColumn("Test property", "Test header"); + + dataGridView.DataSource = new[] { "Test value" }; + var dataGridViewCell = dataGridView.Rows[0].Cells[0]; + dataGridView.CurrentCell = dataGridViewCell; + dataGridView.BeginEdit(false); + + // Call + dataGridViewCell.Value = "New value"; + + // Assert + Assert.AreEqual(string.Empty, dataGridViewCell.OwningRow.ErrorText); + } + } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs =================================================================== diff -u -rf5ac9de8b45cef4515fa7a051c5af54446f96712 -r0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision f5ac9de8b45cef4515fa7a051c5af54446f96712) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3) @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.42000 +// Runtime Version:4.0.30319.17929 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -321,15 +321,6 @@ } /// - /// Looks up a localized string similar to De tekst mag niet leeg zijn.. - /// - public static string DataGridViewCellValidating_Text_may_not_be_empty { - get { - return ResourceManager.GetString("DataGridViewCellValidating_Text_may_not_be_empty", resourceCulture); - } - } - - /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// public static System.Drawing.Bitmap EditDocumentIcon { Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismResultView.cs =================================================================== diff -u -r2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f -r0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismResultView.cs (.../FailureMechanismResultView.cs) (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismResultView.cs (.../FailureMechanismResultView.cs) (revision 0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3) @@ -29,6 +29,7 @@ using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Forms.Properties; using CoreCommonResources = Core.Common.Base.Properties.Resources; +using CoreCommonControlsResources = Core.Common.Controls.Properties.Resources; namespace Ringtoets.Common.Forms.Views { @@ -307,7 +308,7 @@ var cellEditValue = e.FormattedValue.ToString(); if (string.IsNullOrWhiteSpace(cellEditValue)) { - dataGridView.Rows[e.RowIndex].ErrorText = Resources.DataGridViewCellValidating_Text_may_not_be_empty; + dataGridView.Rows[e.RowIndex].ErrorText = CoreCommonControlsResources.DataGridViewCellValidating_Text_may_not_be_empty; } } Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingCalculationsView.cs =================================================================== diff -u -ra1bdc4941a7918bf20b1ea7247a725aa568a2b68 -r0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingCalculationsView.cs (.../PipingCalculationsView.cs) (revision a1bdc4941a7918bf20b1ea7247a725aa568a2b68) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingCalculationsView.cs (.../PipingCalculationsView.cs) (revision 0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3) @@ -39,6 +39,7 @@ using Ringtoets.Piping.Forms.Properties; using Ringtoets.Piping.Service; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; +using CoreCommonControlsResources = Core.Common.Controls.Properties.Resources; namespace Ringtoets.Piping.Forms.Views { @@ -764,7 +765,7 @@ var cellEditValue = e.FormattedValue.ToString(); if (string.IsNullOrWhiteSpace(cellEditValue)) { - dataGridView.Rows[e.RowIndex].ErrorText = RingtoetsCommonFormsResources.DataGridViewCellValidating_Text_may_not_be_empty; + dataGridView.Rows[e.RowIndex].ErrorText = CoreCommonControlsResources.DataGridViewCellValidating_Text_may_not_be_empty; } }