Index: Core/Common/src/Core.Common.Controls/Core.Common.Controls.csproj
===================================================================
diff -u -r183eb0cda52b8014d27bb22ccea6c76d7cc3a1de -red0f008eb876e1ad9b838ce0112a3e80576f3845
--- Core/Common/src/Core.Common.Controls/Core.Common.Controls.csproj (.../Core.Common.Controls.csproj) (revision 183eb0cda52b8014d27bb22ccea6c76d7cc3a1de)
+++ Core/Common/src/Core.Common.Controls/Core.Common.Controls.csproj (.../Core.Common.Controls.csproj) (revision ed0f008eb876e1ad9b838ce0112a3e80576f3845)
@@ -18,6 +18,7 @@
+
Component
@@ -28,6 +29,7 @@
DataGridViewControl.cs
+
Form
Index: Core/Common/src/Core.Common.Controls/DataGrid/DataGridViewControlCellFormatExtensions.cs
===================================================================
diff -u
--- Core/Common/src/Core.Common.Controls/DataGrid/DataGridViewControlCellFormatExtensions.cs (revision 0)
+++ Core/Common/src/Core.Common.Controls/DataGrid/DataGridViewControlCellFormatExtensions.cs (revision ed0f008eb876e1ad9b838ce0112a3e80576f3845)
@@ -0,0 +1,64 @@
+// Copyright (C) Stichting Deltares 2017. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Windows.Forms;
+
+namespace Core.Common.Controls.DataGrid
+{
+ ///
+ /// Extension methods for to format cells.
+ ///
+ public static class DataGridViewControlCellFormatExtensions
+ {
+ ///
+ /// Formats a cell with the properties as defined in .
+ ///
+ /// The type of row that the hosts.
+ /// The that needs to be formatted.
+ /// The row index of the cell that should be formatted.
+ /// The column index of the cell that should be formatted.
+ /// Thrown when
+ /// is null.
+ /// Thrown when the
+ /// or the does not exist.
+ public static void FormatCellWithColumnStateDefinition(this DataGridViewControl dataGridViewControl, int rowIndex, int columnIndex)
+ where TRow : IHasColumnStateDefinitions
+ {
+ if (dataGridViewControl == null)
+ {
+ throw new ArgumentNullException(nameof(dataGridViewControl));
+ }
+
+ var row = (TRow) dataGridViewControl.GetRowFromIndex(rowIndex).DataBoundItem;
+ if (row.ColumnStateDefinitions.ContainsKey(columnIndex))
+ {
+ DataGridViewColumnStateDefinition columnStateDefinition = row.ColumnStateDefinitions[columnIndex];
+ DataGridViewCell cell = dataGridViewControl.GetCell(rowIndex, columnIndex);
+
+ cell.ReadOnly = columnStateDefinition.ReadOnly;
+ cell.ErrorText = columnStateDefinition.ErrorText;
+ cell.Style.BackColor = columnStateDefinition.Style.BackgroundColor;
+ cell.Style.ForeColor = columnStateDefinition.Style.TextColor;
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/src/Core.Common.Controls/DataGrid/IHasColumnStateDefinitions.cs
===================================================================
diff -u
--- Core/Common/src/Core.Common.Controls/DataGrid/IHasColumnStateDefinitions.cs (revision 0)
+++ Core/Common/src/Core.Common.Controls/DataGrid/IHasColumnStateDefinitions.cs (revision ed0f008eb876e1ad9b838ce0112a3e80576f3845)
@@ -0,0 +1,37 @@
+// Copyright (C) Stichting Deltares 2017. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System.Collections.Generic;
+
+namespace Core.Common.Controls.DataGrid
+{
+ ///
+ /// Interface for the row objects in a that have
+ /// .
+ ///
+ public interface IHasColumnStateDefinitions
+ {
+ ///
+ /// Gets the column state definitions.
+ ///
+ IDictionary ColumnStateDefinitions { get; }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.Controls.Test/Core.Common.Controls.Test.csproj
===================================================================
diff -u -r183eb0cda52b8014d27bb22ccea6c76d7cc3a1de -red0f008eb876e1ad9b838ce0112a3e80576f3845
--- Core/Common/test/Core.Common.Controls.Test/Core.Common.Controls.Test.csproj (.../Core.Common.Controls.Test.csproj) (revision 183eb0cda52b8014d27bb22ccea6c76d7cc3a1de)
+++ Core/Common/test/Core.Common.Controls.Test/Core.Common.Controls.Test.csproj (.../Core.Common.Controls.Test.csproj) (revision ed0f008eb876e1ad9b838ce0112a3e80576f3845)
@@ -28,6 +28,7 @@
+
Index: Core/Common/test/Core.Common.Controls.Test/DataGrid/DataGridViewControlCellFormatExtensionsTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.Controls.Test/DataGrid/DataGridViewControlCellFormatExtensionsTest.cs (revision 0)
+++ Core/Common/test/Core.Common.Controls.Test/DataGrid/DataGridViewControlCellFormatExtensionsTest.cs (revision ed0f008eb876e1ad9b838ce0112a3e80576f3845)
@@ -0,0 +1,111 @@
+// Copyright (C) Stichting Deltares 2017. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Collections.Generic;
+using System.Windows.Forms;
+using Core.Common.Base.Data;
+using Core.Common.Controls.DataGrid;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+
+namespace Core.Common.Controls.Test.DataGrid
+{
+ [TestFixture]
+ public class DataGridViewControlCellFormatExtensionsTest
+ {
+ private static IEnumerable CellFormattingStates
+ {
+ get
+ {
+ yield return new TestCaseData(true, "", CellStyle.Disabled);
+ yield return new TestCaseData(false, "Error", CellStyle.Enabled);
+ }
+ }
+
+ [Test]
+ public void FormatCellWithColumnStateDefinition_DataGridViewControlNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => ((DataGridViewControl)null).FormatCellWithColumnStateDefinition(0, 0);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual("dataGridViewControl", exception.ParamName);
+ }
+
+ [Test]
+ [TestCaseSource(nameof(CellFormattingStates))]
+ public void FormatCellWithColumnStateDefinition_WithArguments_FormatsCell(
+ bool isReadOnly, string errorText, CellStyle cellStyle)
+ {
+ // Setup
+ var random = new Random(21);
+ var row = new TestRow(random.NextRoundedDouble());
+ DataGridViewColumnStateDefinition definition = row.ColumnStateDefinitions[0];
+ definition.ReadOnly = isReadOnly;
+ definition.ErrorText = errorText;
+ definition.Style = cellStyle;
+
+ using (var form = new Form())
+ using (var dataGridViewControl = new DataGridViewControl())
+ {
+ form.Controls.Add(dataGridViewControl);
+ form.Show();
+
+ dataGridViewControl.AddTextBoxColumn(nameof(TestRow.TestRoundedDouble), "Test");
+ dataGridViewControl.SetDataSource(new[]
+ {
+ row
+ });
+
+ // Call
+ dataGridViewControl.FormatCellWithColumnStateDefinition(0, 0);
+
+ // Assert
+ DataGridViewCell cell = dataGridViewControl.Rows[0].Cells[0];
+ Assert.AreEqual(isReadOnly, cell.ReadOnly);
+ Assert.AreEqual(errorText, cell.ErrorText);
+ Assert.AreEqual(cellStyle.BackgroundColor, cell.Style.BackColor);
+ Assert.AreEqual(cellStyle.TextColor, cell.Style.ForeColor);
+ }
+ }
+
+ private class TestRow : IHasColumnStateDefinitions
+ {
+ public TestRow(RoundedDouble testRoundedDouble)
+ {
+ TestRoundedDouble = testRoundedDouble;
+ ColumnStateDefinitions = new Dictionary
+ {
+ {
+ 0, new DataGridViewColumnStateDefinition()
+ }
+ };
+ }
+
+ // Property needs to have a setter, otherwise some tests will fail
+ public RoundedDouble TestRoundedDouble { get; set; }
+
+ public IDictionary ColumnStateDefinitions { get; }
+ }
+ }
+}
\ No newline at end of file