Index: Core/Common/src/Core.Common.Controls/Core.Common.Controls.csproj =================================================================== diff -u -rf1be6965092b5dc1b0e2e145d59e718493351fb8 -ra048dc4662f1eb83e4e8cd127790473f01470263 --- Core/Common/src/Core.Common.Controls/Core.Common.Controls.csproj (.../Core.Common.Controls.csproj) (revision f1be6965092b5dc1b0e2e145d59e718493351fb8) +++ Core/Common/src/Core.Common.Controls/Core.Common.Controls.csproj (.../Core.Common.Controls.csproj) (revision a048dc4662f1eb83e4e8cd127790473f01470263) @@ -81,6 +81,7 @@ Properties\GlobalAssembly.cs + UserControl Index: Core/Common/src/Core.Common.Controls/DataGrid/CellStyle.cs =================================================================== diff -u --- Core/Common/src/Core.Common.Controls/DataGrid/CellStyle.cs (revision 0) +++ Core/Common/src/Core.Common.Controls/DataGrid/CellStyle.cs (revision a048dc4662f1eb83e4e8cd127790473f01470263) @@ -0,0 +1,52 @@ +// Copyright (C) Stichting Deltares 2016. 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.Drawing; + +namespace Core.Common.Controls.DataGrid +{ + /// + /// Class describing the different cell styles for the . + /// + public class CellStyle + { + /// + /// The cell style for enabled cells. + /// + public static readonly CellStyle Enabled = new CellStyle + { + TextColor = Color.FromKnownColor(KnownColor.ControlText), + BackgroundColor = Color.FromKnownColor(KnownColor.White) + }; + + /// + /// The cell style of disabled cells. + /// + public static readonly CellStyle Disabled = new CellStyle + { + TextColor = Color.FromKnownColor(KnownColor.GrayText), + BackgroundColor = Color.FromKnownColor(KnownColor.DarkGray) + }; + + public Color TextColor { get; private set; } + public Color BackgroundColor { get; private set; } + } +} \ No newline at end of file Index: Core/Common/src/Core.Common.Controls/DataGrid/DataGridViewControl.Designer.cs =================================================================== diff -u -rf1be6965092b5dc1b0e2e145d59e718493351fb8 -ra048dc4662f1eb83e4e8cd127790473f01470263 --- Core/Common/src/Core.Common.Controls/DataGrid/DataGridViewControl.Designer.cs (.../DataGridViewControl.Designer.cs) (revision f1be6965092b5dc1b0e2e145d59e718493351fb8) +++ Core/Common/src/Core.Common.Controls/DataGrid/DataGridViewControl.Designer.cs (.../DataGridViewControl.Designer.cs) (revision a048dc4662f1eb83e4e8cd127790473f01470263) @@ -36,7 +36,7 @@ // // dataGridView // - this.dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader; + this.dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; this.dataGridView.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing; this.dataGridView.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -51,6 +51,7 @@ this.dataGridView.AllowUserToAddRows = false; this.dataGridView.AllowUserToDeleteRows = false; this.dataGridView.StandardTab = true; + this.dataGridView.AutoGenerateColumns = false; // // DataGridViewControl // Index: Core/Common/src/Core.Common.Controls/DataGrid/DataGridViewControl.cs =================================================================== diff -u -r0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3 -ra048dc4662f1eb83e4e8cd127790473f01470263 --- Core/Common/src/Core.Common.Controls/DataGrid/DataGridViewControl.cs (.../DataGridViewControl.cs) (revision 0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3) +++ Core/Common/src/Core.Common.Controls/DataGrid/DataGridViewControl.cs (.../DataGridViewControl.cs) (revision a048dc4662f1eb83e4e8cd127790473f01470263) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.Windows.Forms; using Core.Common.Controls.Properties; @@ -81,20 +82,124 @@ /// /// The of the column. /// The of the column. + /// /// is also used to create the . /// The format is "column_. - public void AddComboBoxColumn(string dataPropertyName, string headerText) + public void AddComboBoxColumn(string dataPropertyName, string headerText, List dataSource = null) { dataGridView.Columns.Add(new DataGridViewComboBoxColumn { DataPropertyName = dataPropertyName, HeaderText = headerText, Name = string.Format("column_{0}", dataPropertyName), - ValueMember = "This", - DisplayMember = "DisplayName" + ValueMember = "Value", + DisplayMember = "DisplayName", + DataSource = dataSource }); } + /// + /// Sets the datasource on the . + /// + /// The datasource to set. + public void SetDataSource(object dataSource) + { + dataGridView.DataSource = dataSource; + } + + /// + /// Refreshes the and performs an . + /// + public void RefreshDataGridView() + { + dataGridView.Refresh(); + dataGridView.AutoResizeColumns(); + } + + /// + /// Ends the editing when the current cell is in edit mode. + /// Sets the current cell to null. + /// + public void EndEdit() + { + if (dataGridView.IsCurrentCellInEditMode) + { + dataGridView.CancelEdit(); + dataGridView.EndEdit(); + dataGridView.CurrentCell = null; + } + } + + /// + /// Gets the on the given index. + /// + /// The index of the row. + /// A . + /// Thrown when the index of the row does not exist. + public DataGridViewRow GetRowFromIndex(int rowIndex) + { + return dataGridView.Rows[rowIndex]; + } + + /// + /// Gets the on the given row and column index. + /// + /// The index of the row the cell is on. + /// The index of the column. + /// A . + /// Thrown when the index of the row or column does not exist. + public DataGridViewCell GetCell(int rowIndex, int columnIndex) + { + return GetRowFromIndex(rowIndex).Cells[columnIndex]; + } + + #region Styling + + /// + /// Restore the initial style of the cell at , . + /// + /// The row index of the cell. + /// The column index of the cell. + /// Indicates wether the column should be read-only. + public void RestoreCell(int rowIndex, int columnIndex, bool readOnly = false) + { + var cell = GetCell(rowIndex, columnIndex); + cell.ReadOnly = readOnly; + SetCellStyle(cell, CellStyle.Enabled); + } + + /// + /// Gives the cell at , a + /// disabled style. + /// + /// The row index of the cell. + /// The column index of the cell. + public void DisableCell(int rowIndex, int columnIndex) + { + var cell = GetCell(rowIndex, columnIndex); + cell.ReadOnly = true; + SetCellStyle(cell, CellStyle.Disabled); + } + + private void SetCellStyle(DataGridViewCell cell, CellStyle style) + { + cell.Style.BackColor = style.BackgroundColor; + cell.Style.ForeColor = style.TextColor; + } + + #endregion + + #region Event handling + + /// + /// Add a handler for the event. + /// + /// The handler to add. + public void AddCellFormattingHandler(DataGridViewCellFormattingEventHandler handler) + { + dataGridView.CellFormatting += handler; + } + private void SubscribeEvents() { dataGridView.CurrentCellDirtyStateChanged += DataGridViewOnCurrentCellDirtyStateChanged; @@ -103,8 +208,6 @@ dataGridView.DataError += DataGridViewOnDataError; } - #region Event handling - private void DataGridViewOnCurrentCellDirtyStateChanged(object sender, EventArgs e) { // Ensure checkbox values are directly committed Index: Core/Common/test/Core.Common.Controls.Test/Core.Common.Controls.Test.csproj =================================================================== diff -u -rf1be6965092b5dc1b0e2e145d59e718493351fb8 -ra048dc4662f1eb83e4e8cd127790473f01470263 --- Core/Common/test/Core.Common.Controls.Test/Core.Common.Controls.Test.csproj (.../Core.Common.Controls.Test.csproj) (revision f1be6965092b5dc1b0e2e145d59e718493351fb8) +++ Core/Common/test/Core.Common.Controls.Test/Core.Common.Controls.Test.csproj (.../Core.Common.Controls.Test.csproj) (revision a048dc4662f1eb83e4e8cd127790473f01470263) @@ -53,6 +53,7 @@ + Index: Core/Common/test/Core.Common.Controls.Test/DataGrid/CellStyleTest.cs =================================================================== diff -u --- Core/Common/test/Core.Common.Controls.Test/DataGrid/CellStyleTest.cs (revision 0) +++ Core/Common/test/Core.Common.Controls.Test/DataGrid/CellStyleTest.cs (revision a048dc4662f1eb83e4e8cd127790473f01470263) @@ -0,0 +1,53 @@ +// Copyright (C) Stichting Deltares 2016. 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.Drawing; +using Core.Common.Controls.DataGrid; +using NUnit.Framework; + +namespace Core.Common.Controls.Test.DataGrid +{ + [TestFixture] + public class CellStyleTest + { + [Test] + public void CellStyleEnabled_Always_ReturnsEnabledStyle() + { + // Call + var cellStyle = CellStyle.Enabled; + + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.White), cellStyle.BackgroundColor); + Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), cellStyle.TextColor); + } + + [Test] + public void CellStyleDisabled_Always_ReturnsDisabledStyle() + { + // Call + var cellStyle = CellStyle.Disabled; + + // Assert + Assert.AreEqual(Color.FromKnownColor(KnownColor.DarkGray), cellStyle.BackgroundColor); + Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), cellStyle.TextColor); + } + } +} \ No newline at end of file Index: Core/Common/test/Core.Common.Controls.Test/DataGrid/DataGridViewControlTest.cs =================================================================== diff -u -r0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3 -ra048dc4662f1eb83e4e8cd127790473f01470263 --- Core/Common/test/Core.Common.Controls.Test/DataGrid/DataGridViewControlTest.cs (.../DataGridViewControlTest.cs) (revision 0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3) +++ Core/Common/test/Core.Common.Controls.Test/DataGrid/DataGridViewControlTest.cs (.../DataGridViewControlTest.cs) (revision a048dc4662f1eb83e4e8cd127790473f01470263) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Drawing; using System.Windows.Forms; using Core.Common.Controls.DataGrid; using NUnit.Extensions.Forms; @@ -61,7 +62,7 @@ // Assert Assert.AreEqual(0, dataGridView.ColumnCount); - Assert.AreEqual(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader, dataGridView.AutoSizeColumnsMode); + Assert.AreEqual(DataGridViewAutoSizeColumnsMode.AllCells, dataGridView.AutoSizeColumnsMode); Assert.AreEqual(DataGridViewContentAlignment.MiddleCenter, dataGridView.ColumnHeadersDefaultCellStyle.Alignment); Assert.AreEqual(DataGridViewEditMode.EditOnEnter, dataGridView.EditMode); Assert.AreEqual(DataGridViewColumnHeadersHeightSizeMode.AutoSize, dataGridView.ColumnHeadersHeightSizeMode); @@ -70,6 +71,7 @@ Assert.IsFalse(dataGridView.AllowUserToResizeRows); Assert.IsFalse(dataGridView.AllowUserToAddRows); Assert.IsFalse(dataGridView.AllowUserToDeleteRows); + Assert.IsFalse(dataGridView.AutoGenerateColumns); Assert.IsTrue(dataGridView.StandardTab); } } @@ -167,12 +169,335 @@ Assert.AreEqual(propertyName, columnData.DataPropertyName); Assert.AreEqual(string.Format("column_{0}", propertyName), columnData.Name); Assert.AreEqual(headerText, columnData.HeaderText); - Assert.AreEqual("This", columnData.ValueMember); + Assert.AreEqual("Value", columnData.ValueMember); Assert.AreEqual("DisplayName", columnData.DisplayMember); } } [Test] + public void SetDataSource_Always_SetsDataSourceOnDataGridView() + { + // 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; + + control.AddCheckBoxColumn("Test property", "Test header"); + + var dataSource = new[] + { + false + }; + + // Call + control.SetDataSource(dataSource); + + // Assert + Assert.AreEqual(dataSource, dataGridView.DataSource); + } + } + + [Test] + public void EndEdit_CurrentCellInEditMode_EndEditAndSetCurrentCellToNull() + { + // 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; + dataGridView.BeginEdit(false); + + // Precondition + Assert.IsTrue(dataGridView.IsCurrentCellInEditMode); + + // Call + control.EndEdit(); + + // Assert + Assert.IsFalse(dataGridView.IsCurrentCellInEditMode); + Assert.IsNull(dataGridView.CurrentCell); + } + } + + [Test] + public void GetRowFromIndex_RowDoesExist_ReturnsRow() + { + // 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; + + control.AddTextBoxColumn("Test property", "Test header"); + + dataGridView.DataSource = new[] { "" }; + + // Call + DataGridViewRow row = control.GetRowFromIndex(0); + + // Assert + Assert.IsNotNull(row); + } + } + + [Test] + public void GetRowFromIndex_RowDoesNotExist_ThrowsArgumentOutOfRangeException() + { + // 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; + + control.AddTextBoxColumn("Test property", "Test header"); + + dataGridView.DataSource = new[] { "" }; + + // Call + TestDelegate call = () => control.GetRowFromIndex(5); + + // Assert + Assert.Throws(call); + } + } + + [Test] + public void GetCell_RowAndCellDoesExist_ReturnsCell() + { + // 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; + + control.AddTextBoxColumn("Test property", "Test header"); + + dataGridView.DataSource = new[] { "" }; + + // Call + DataGridViewCell cell = control.GetCell(0, 0); + + // Assert + Assert.IsNotNull(cell); + } + } + + [Test] + public void GetCell_RowDoesNotExist_ThrowsArgumentOutOfRangeException() + { + // 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; + + control.AddTextBoxColumn("Test property", "Test header"); + + dataGridView.DataSource = new[] { "" }; + + // Call + TestDelegate call = () => control.GetCell(5, 0); + + // Assert + Assert.Throws(call); + } + } + + [Test] + public void GetCell_CellDoesNotExist_ThrowsArgumentOutOfRangeException() + { + // 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; + + control.AddTextBoxColumn("Test property", "Test header"); + + dataGridView.DataSource = new[] { "" }; + + // Call + TestDelegate call = () => control.GetCell(0, 5); + + // Assert + Assert.Throws(call); + } + } + + [Test] + public void DisableCell_Always_DisablesCell() + { + // 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; + + control.AddTextBoxColumn("Test property", "Test header"); + + dataGridView.DataSource = new[] { "" }; + + // Call + control.DisableCell(0, 0); + + // Assert + var dataGridViewCell = dataGridView.Rows[0].Cells[0]; + Assert.IsTrue(dataGridViewCell.ReadOnly); + Assert.AreEqual(Color.FromKnownColor(KnownColor.DarkGray), dataGridViewCell.Style.BackColor); + Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), dataGridViewCell.Style.ForeColor); + } + } + + [Test] + public void RestoreCell_ReadOnlyFalse_SetsCellStyleToEnabledWithReadOnlyFalse() + { + // 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; + + control.AddTextBoxColumn("Test property", "Test header"); + + dataGridView.DataSource = new[] { "" }; + + control.DisableCell(0, 0); + + // Precondition + var dataGridViewCell = dataGridView.Rows[0].Cells[0]; + Assert.IsTrue(dataGridViewCell.ReadOnly); + Assert.AreEqual(Color.FromKnownColor(KnownColor.DarkGray), dataGridViewCell.Style.BackColor); + Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), dataGridViewCell.Style.ForeColor); + + // Call + control.RestoreCell(0, 0, false); + + // Assert + Assert.IsFalse(dataGridViewCell.ReadOnly); + Assert.AreEqual(Color.FromKnownColor(KnownColor.White), dataGridViewCell.Style.BackColor); + Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), dataGridViewCell.Style.ForeColor); + } + } + + [Test] + public void RestoreCell_ReadOnlyTrue_SetsCellStyleToEnabledWithReadOnlyTrue() + { + // 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; + + control.AddTextBoxColumn("Test property", "Test header"); + + dataGridView.DataSource = new[] { "" }; + + control.DisableCell(0, 0); + + // Precondition + var dataGridViewCell = dataGridView.Rows[0].Cells[0]; + Assert.IsTrue(dataGridViewCell.ReadOnly); + Assert.AreEqual(Color.FromKnownColor(KnownColor.DarkGray), dataGridViewCell.Style.BackColor); + Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), dataGridViewCell.Style.ForeColor); + + // Call + control.RestoreCell(0, 0, true); + + // Assert + Assert.IsTrue(dataGridViewCell.ReadOnly); + Assert.AreEqual(Color.FromKnownColor(KnownColor.White), dataGridViewCell.Style.BackColor); + Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), dataGridViewCell.Style.ForeColor); + } + } + + #region Event handling + + [Test] + public void AddCellFormattingHandler_Always_AddsEventHandler() + { + // 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; + + control.AddTextBoxColumn("Test property", "Test header"); + + dataGridView.DataSource = new[] { "" }; + var dataGridViewCell = dataGridView.Rows[0].Cells[0]; + dataGridView.CurrentCell = dataGridViewCell; + + int counter = 0; + + control.AddCellFormattingHandler((sender, args) => counter++); + + // Precondition + Assert.AreEqual(0, counter); + + // Call + var formattedValue = dataGridViewCell.FormattedValue; // Need to do this to fire the CellFormatting event. + + // Assert + Assert.AreEqual(1, counter); + } + } + + [Test] public void DataGridViewControlCheckBoxColumn_EditValueDirtyStateChangedEventFired_ValueCommittedCellInEditMode() { // Setup @@ -302,5 +627,7 @@ Assert.AreEqual(string.Empty, dataGridViewCell.OwningRow.ErrorText); } } + + #endregion } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismResultView.Designer.cs =================================================================== diff -u -rea99af5c043eadf5c2ba83b82a847ae009181191 -ra048dc4662f1eb83e4e8cd127790473f01470263 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismResultView.Designer.cs (.../FailureMechanismResultView.Designer.cs) (revision ea99af5c043eadf5c2ba83b82a847ae009181191) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismResultView.Designer.cs (.../FailureMechanismResultView.Designer.cs) (revision a048dc4662f1eb83e4e8cd127790473f01470263) @@ -15,48 +15,27 @@ /// private void InitializeComponent() { - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.DataGridViewControl = new Core.Common.Controls.DataGrid.DataGridViewControl(); this.SuspendLayout(); // - // dataGridView + // dataGridViewControl // - this.dataGridView.AllowUserToAddRows = false; - this.dataGridView.AllowUserToDeleteRows = false; - this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells; - dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; - dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control; - dataGridViewCellStyle1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText; - dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.dataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Dock = System.Windows.Forms.DockStyle.Fill; - this.dataGridView.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter; - this.dataGridView.Location = new System.Drawing.Point(0, 0); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.Size = new System.Drawing.Size(150, 150); - this.dataGridView.TabIndex = 0; - this.dataGridView.CellValidating += new System.Windows.Forms.DataGridViewCellValidatingEventHandler(this.DataGridViewCellValidating); - this.dataGridView.CurrentCellDirtyStateChanged += new System.EventHandler(this.DataGridViewCurrentCellDirtyStateChanged); - this.dataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.DataGridViewDataError); + this.DataGridViewControl.Dock = System.Windows.Forms.DockStyle.Fill; + this.DataGridViewControl.Location = new System.Drawing.Point(0, 0); + this.DataGridViewControl.Name = "DataGridViewControl"; + this.DataGridViewControl.Size = new System.Drawing.Size(150, 150); + this.DataGridViewControl.TabIndex = 0; // // FailureMechanismResultView // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.dataGridView); + this.Controls.Add(this.DataGridViewControl); this.Name = "FailureMechanismResultView"; - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); } #endregion - - private System.Windows.Forms.DataGridView dataGridView; } } Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismResultView.cs =================================================================== diff -u -r0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3 -ra048dc4662f1eb83e4e8cd127790473f01470263 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismResultView.cs (.../FailureMechanismResultView.cs) (revision 0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/FailureMechanismResultView.cs (.../FailureMechanismResultView.cs) (revision a048dc4662f1eb83e4e8cd127790473f01470263) @@ -19,12 +19,11 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using System.Collections.Generic; -using System.Drawing; using System.Linq; using System.Windows.Forms; using Core.Common.Base; +using Core.Common.Controls.DataGrid; using Core.Common.Controls.Views; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Forms.Properties; @@ -38,9 +37,9 @@ /// public abstract partial class FailureMechanismResultView : UserControl, IView where T : FailureMechanismSectionResult { + private const int assessmentLayerOneColumnIndex = 1; private readonly IList failureMechanismSectionResultObservers; private readonly Observer failureMechanismObserver; - private const int assessmentLayerOneColumnIndex = 1; private IEnumerable failureMechanismSectionResult; private IFailureMechanism failureMechanism; @@ -85,11 +84,13 @@ } else { - dataGridView.DataSource = null; + DataGridViewControl.SetDataSource(null); } } } + protected DataGridViewControl DataGridViewControl { get; private set; } + protected override void Dispose(bool disposing) { FailureMechanism = null; @@ -108,85 +109,33 @@ /// /// Finds out whether the assessment section which is represented by the row at index - /// has passed the level 0 assessment. + /// has passed the level 1 assessment. /// /// The index of the row which has a section attached. - /// false if assessment level 0 has passed, true otherwise. - protected bool HasPassedLevelZero(int rowIndex) + /// false if assessment level 1 has passed, true otherwise. + protected bool HasPassedLevelOne(int rowIndex) { - var row = dataGridView.Rows[rowIndex]; - return (bool) row.Cells[assessmentLayerOneColumnIndex].Value; + return (bool) DataGridViewControl.GetCell(rowIndex, assessmentLayerOneColumnIndex).Value; } /// - /// Add a handler for the event. - /// - /// The handler to add. - protected void AddCellFormattingHandler(DataGridViewCellFormattingEventHandler handler) - { - dataGridView.CellFormatting += handler; - } - - /// - /// Restore the initial style of the cell at , . - /// - /// The row index of the cell. - /// The column index of the cell. - protected void RestoreCell(int rowIndex, int columnIndex) - { - var cell = dataGridView.Rows[rowIndex].Cells[columnIndex]; - cell.ReadOnly = GetDataGridColumns().ElementAt(columnIndex).ReadOnly; - SetCellStyle(cell, CellStyle.Enabled); - } - - /// - /// Gives the cell at , a - /// disabled style. - /// - /// The row index of the cell. - /// The column index of the cell. - protected void DisableCell(int rowIndex, int columnIndex) - { - var cell = GetCell(rowIndex, columnIndex); - cell.ReadOnly = true; - SetCellStyle(cell, CellStyle.Disabled); - } - - protected DataGridViewCell GetCell(int rowIndex, int columnIndex) - { - return dataGridView.Rows[rowIndex].Cells[columnIndex]; - } - - /// /// Gets all the columns that should be added to the on the /// . /// /// An of . - protected virtual IEnumerable GetDataGridColumns() + protected virtual void AddDataGridColumns() { - yield return new DataGridViewTextBoxColumn - { - DataPropertyName = "Name", - HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Section_name, - Name = "column_Name", - ReadOnly = true - }; - - yield return new DataGridViewCheckBoxColumn - { - DataPropertyName = "AssessmentLayerOne", - HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_one, - Name = "column_AssessmentLayerOne" - }; + DataGridViewControl.AddTextBoxColumn("Name", Resources.FailureMechanismResultView_InitializeDataGridView_Section_name, true); + DataGridViewControl.AddCheckBoxColumn("AssessmentLayerOne", Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_one); } /// /// Updates the data source of the data grid view with the current known failure mechanism section results. /// protected void UpdataDataGridViewDataSource() { - EndEdit(); - dataGridView.DataSource = failureMechanismSectionResult.Select(CreateFailureMechanismSectionResultRow).ToList(); + DataGridViewControl.EndEdit(); + DataGridViewControl.SetDataSource(failureMechanismSectionResult.Select(CreateFailureMechanismSectionResultRow).ToList()); } /// @@ -196,7 +145,7 @@ /// The data bound to the row at index . protected object GetDataAtRow(int rowIndex) { - return dataGridView.Rows[rowIndex].DataBoundItem; + return DataGridViewControl.GetRowFromIndex(rowIndex).DataBoundItem; } /// @@ -222,23 +171,11 @@ } } - private void SetCellStyle(DataGridViewCell cell, CellStyle style) - { - cell.Style.BackColor = style.BackgroundColor; - cell.Style.ForeColor = style.TextColor; - } - - private void RefreshDataGridView() - { - dataGridView.Refresh(); - dataGridView.AutoResizeColumns(); - } - private void AddSectionResultObservers() { foreach (var sectionResult in failureMechanismSectionResult) { - failureMechanismSectionResultObservers.Add(new Observer(RefreshDataGridView) + failureMechanismSectionResultObservers.Add(new Observer(DataGridViewControl.RefreshDataGridView) { Observable = sectionResult }); @@ -256,81 +193,7 @@ private void InitializeDataGridView() { - dataGridView.GotFocus += DataGridViewGotFocus; - dataGridView.AutoGenerateColumns = false; - dataGridView.Columns.AddRange(GetDataGridColumns().ToArray()); + AddDataGridColumns(); } - - private void EndEdit() - { - if (dataGridView.IsCurrentCellInEditMode) - { - dataGridView.CancelEdit(); - dataGridView.EndEdit(); - dataGridView.CurrentCell = null; - } - } - - private class CellStyle - { - public static readonly CellStyle Enabled = new CellStyle - { - TextColor = Color.FromKnownColor(KnownColor.ControlText), - BackgroundColor = Color.FromKnownColor(KnownColor.White) - }; - - public static readonly CellStyle Disabled = new CellStyle - { - TextColor = Color.FromKnownColor(KnownColor.GrayText), - BackgroundColor = Color.FromKnownColor(KnownColor.DarkGray) - }; - - public Color TextColor { get; private set; } - public Color BackgroundColor { get; private set; } - } - - #region Event handling - - private void DataGridViewCurrentCellDirtyStateChanged(object sender, EventArgs e) - { - // Ensure checkbox values are directly committed - DataGridViewColumn currentColumn = dataGridView.Columns[dataGridView.CurrentCell.ColumnIndex]; - if (currentColumn is DataGridViewCheckBoxColumn) - { - dataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit); - } - } - - private void DataGridViewCellValidating(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 = CoreCommonControlsResources.DataGridViewCellValidating_Text_may_not_be_empty; - } - } - - private void DataGridViewDataError(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; - } - } - - private void DataGridViewGotFocus(object sender, EventArgs eventArgs) - { - 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...) - } - } - - #endregion } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismResultView.cs =================================================================== diff -u -r219f8633c1b5b24f9e9aec3e903734fa94775f0e -ra048dc4662f1eb83e4e8cd127790473f01470263 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismResultView.cs (.../GrassCoverErosionInwardsFailureMechanismResultView.cs) (revision 219f8633c1b5b24f9e9aec3e903734fa94775f0e) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismResultView.cs (.../GrassCoverErosionInwardsFailureMechanismResultView.cs) (revision a048dc4662f1eb83e4e8cd127790473f01470263) @@ -19,7 +19,6 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using Core.Common.Base; @@ -41,12 +40,14 @@ private readonly RecursiveObserver calculationOutputObserver; private readonly RecursiveObserver calculationGroupObserver; + private int assessmentLayerTwoAIndex = 2; + /// /// Creates a new instance of . /// public GrassCoverErosionInwardsFailureMechanismResultView() { - AddCellFormattingHandler(DisableIrrelevantFieldsFormatting); + DataGridViewControl.AddCellFormattingHandler(DisableIrrelevantFieldsFormatting); // The concat is needed to observe the input of calculations in child groups. calculationInputObserver = new RecursiveObserver(UpdataDataGridViewDataSource, cg => cg.Children.Concat(cg.Children.OfType().Select(c => c.GetObservableInput()))); @@ -78,34 +79,13 @@ base.Dispose(disposing); } - protected override IEnumerable GetDataGridColumns() + protected override void AddDataGridColumns() { - foreach (var baseColumn in base.GetDataGridColumns()) - { - yield return baseColumn; - } + base.AddDataGridColumns(); - yield return new DataGridViewTextBoxColumn - { - DataPropertyName = "AssessmentLayerTwoA", - HeaderText = RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_a, - Name = "column_AssessmentLayerTwoA", - ReadOnly = true - }; - - yield return new DataGridViewTextBoxColumn - { - DataPropertyName = "AssessmentLayerTwoB", - HeaderText = RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_b, - Name = "column_AssessmentLayerTwoB" - }; - - yield return new DataGridViewTextBoxColumn - { - DataPropertyName = "AssessmentLayerThree", - HeaderText = RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_three, - Name = "column_AssessmentLayerThree" - }; + DataGridViewControl.AddTextBoxColumn("AssessmentLayerTwoA", RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_a, true); + DataGridViewControl.AddTextBoxColumn("AssessmentLayerTwoB", RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_b); + DataGridViewControl.AddTextBoxColumn("AssessmentLayerThree", RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_three); } protected override object CreateFailureMechanismSectionResultRow(GrassCoverErosionInwardsFailureMechanismSectionResult sectionResult) @@ -117,13 +97,13 @@ { if (eventArgs.ColumnIndex > 1) { - if (HasPassedLevelZero(eventArgs.RowIndex)) + if (HasPassedLevelOne(eventArgs.RowIndex)) { - DisableCell(eventArgs.RowIndex, eventArgs.ColumnIndex); + DataGridViewControl.DisableCell(eventArgs.RowIndex, eventArgs.ColumnIndex); } else { - RestoreCell(eventArgs.RowIndex, eventArgs.ColumnIndex); + DataGridViewControl.RestoreCell(eventArgs.RowIndex, eventArgs.ColumnIndex, eventArgs.ColumnIndex == assessmentLayerTwoAIndex); } } } Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Views/HeightStructuresFailureMechanismResultView.cs =================================================================== diff -u -r3280840f72a6c61740b803385f3af8ec1f6ede91 -ra048dc4662f1eb83e4e8cd127790473f01470263 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Views/HeightStructuresFailureMechanismResultView.cs (.../HeightStructuresFailureMechanismResultView.cs) (revision 3280840f72a6c61740b803385f3af8ec1f6ede91) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Views/HeightStructuresFailureMechanismResultView.cs (.../HeightStructuresFailureMechanismResultView.cs) (revision a048dc4662f1eb83e4e8cd127790473f01470263) @@ -19,7 +19,6 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using Core.Common.Base; @@ -41,12 +40,14 @@ private readonly RecursiveObserver calculationOutputObserver; private readonly RecursiveObserver calculationGroupObserver; + private int assessmentLayerTwoAIndex = 2; + /// /// Creates a new instance of . /// public HeightStructuresFailureMechanismResultView() { - AddCellFormattingHandler(DisableIrrelevantFieldsFormatting); + DataGridViewControl.AddCellFormattingHandler(DisableIrrelevantFieldsFormatting); // The concat is needed to observe the input of calculations in child groups. calculationInputObserver = new RecursiveObserver(UpdataDataGridViewDataSource, cg => cg.Children.Concat(cg.Children.OfType().Select(c => c.GetObservableInput()))); @@ -82,45 +83,24 @@ { if (eventArgs.ColumnIndex > 1) { - if (HasPassedLevelZero(eventArgs.RowIndex)) + if (HasPassedLevelOne(eventArgs.RowIndex)) { - DisableCell(eventArgs.RowIndex, eventArgs.ColumnIndex); + DataGridViewControl.DisableCell(eventArgs.RowIndex, eventArgs.ColumnIndex); } else { - RestoreCell(eventArgs.RowIndex, eventArgs.ColumnIndex); + DataGridViewControl.RestoreCell(eventArgs.RowIndex, eventArgs.ColumnIndex, eventArgs.ColumnIndex == assessmentLayerTwoAIndex); } } } - protected override IEnumerable GetDataGridColumns() + protected override void AddDataGridColumns() { - foreach (var baseColumn in base.GetDataGridColumns()) - { - yield return baseColumn; - } + base.AddDataGridColumns(); - yield return new DataGridViewTextBoxColumn - { - DataPropertyName = "AssessmentLayerTwoA", - HeaderText = RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_a, - Name = "column_AssessmentLayerTwoA", - ReadOnly = true - }; - - yield return new DataGridViewTextBoxColumn - { - DataPropertyName = "AssessmentLayerTwoB", - HeaderText = RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_b, - Name = "column_AssessmentLayerTwoB" - }; - - yield return new DataGridViewTextBoxColumn - { - DataPropertyName = "AssessmentLayerThree", - HeaderText = RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_three, - Name = "column_AssessmentLayerThree" - }; + DataGridViewControl.AddTextBoxColumn("AssessmentLayerTwoA", RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_a, true); + DataGridViewControl.AddTextBoxColumn("AssessmentLayerTwoB", RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_b); + DataGridViewControl.AddTextBoxColumn("AssessmentLayerThree", RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_three); } protected override object CreateFailureMechanismSectionResultRow(HeightStructuresFailureMechanismSectionResult sectionResult) Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/StandAloneFailureMechanismContextProperties.cs =================================================================== diff -u -rdaa1008263412accdb1fcad949ddf100fb2e97b7 -ra048dc4662f1eb83e4e8cd127790473f01470263 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/StandAloneFailureMechanismContextProperties.cs (.../StandAloneFailureMechanismContextProperties.cs) (revision daa1008263412accdb1fcad949ddf100fb2e97b7) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/PropertyClasses/StandAloneFailureMechanismContextProperties.cs (.../StandAloneFailureMechanismContextProperties.cs) (revision a048dc4662f1eb83e4e8cd127790473f01470263) @@ -1,3 +1,24 @@ +// Copyright (C) Stichting Deltares 2016. 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 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 General Public License for more details. +// +// You should have received a copy of the GNU 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 Core.Common.Gui.Attributes; using Core.Common.Gui.PropertyBag; using Core.Common.Utils.Attributes; Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/CustomFailureMechanismResultView.cs =================================================================== diff -u -r2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f -ra048dc4662f1eb83e4e8cd127790473f01470263 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/CustomFailureMechanismResultView.cs (.../CustomFailureMechanismResultView.cs) (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/CustomFailureMechanismResultView.cs (.../CustomFailureMechanismResultView.cs) (revision a048dc4662f1eb83e4e8cd127790473f01470263) @@ -1,8 +1,28 @@ -using System.Collections.Generic; +// Copyright (C) Stichting Deltares 2016. 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 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 General Public License for more details. +// +// You should have received a copy of the GNU 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.Windows.Forms; using Ringtoets.Common.Data.FailureMechanism; -using Ringtoets.Common.Forms.Properties; using Ringtoets.Common.Forms.Views; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.Integration.Forms.Views { @@ -17,51 +37,31 @@ /// public CustomFailureMechanismResultView() { - AddCellFormattingHandler(OnCellFormatting); + DataGridViewControl.AddCellFormattingHandler(OnCellFormatting); } private void OnCellFormatting(object sender, DataGridViewCellFormattingEventArgs eventArgs) { if (eventArgs.ColumnIndex > 1) { - if (HasPassedLevelZero(eventArgs.RowIndex)) + if (HasPassedLevelOne(eventArgs.RowIndex)) { - DisableCell(eventArgs.RowIndex, eventArgs.ColumnIndex); + DataGridViewControl.DisableCell(eventArgs.RowIndex, eventArgs.ColumnIndex); } else { - RestoreCell(eventArgs.RowIndex, eventArgs.ColumnIndex); + DataGridViewControl.RestoreCell(eventArgs.RowIndex, eventArgs.ColumnIndex); } } } - protected override IEnumerable GetDataGridColumns() + protected override void AddDataGridColumns() { - foreach (var baseColumn in base.GetDataGridColumns()) - { - yield return baseColumn; - } + base.AddDataGridColumns(); - yield return new DataGridViewTextBoxColumn - { - DataPropertyName = "AssessmentLayerTwoA", - HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_a, - Name = "column_AssessmentLayerTwoA" - }; - - yield return new DataGridViewTextBoxColumn - { - DataPropertyName = "AssessmentLayerTwoB", - HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_b, - Name = "column_AssessmentLayerTwoB" - }; - - yield return new DataGridViewTextBoxColumn - { - DataPropertyName = "AssessmentLayerThree", - HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_three, - Name = "column_AssessmentLayerThree" - }; + DataGridViewControl.AddTextBoxColumn("AssessmentLayerTwoA", RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_a); + DataGridViewControl.AddTextBoxColumn("AssessmentLayerTwoB", RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_b); + DataGridViewControl.AddTextBoxColumn("AssessmentLayerThree", RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_three); } protected override object CreateFailureMechanismSectionResultRow(CustomFailureMechanismSectionResult sectionResult) Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/CustomProbabilityFailureMechanismResultView.cs =================================================================== diff -u -r22c0ecd4c314c3e38e94d79ccad6735ecf165feb -ra048dc4662f1eb83e4e8cd127790473f01470263 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/CustomProbabilityFailureMechanismResultView.cs (.../CustomProbabilityFailureMechanismResultView.cs) (revision 22c0ecd4c314c3e38e94d79ccad6735ecf165feb) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/CustomProbabilityFailureMechanismResultView.cs (.../CustomProbabilityFailureMechanismResultView.cs) (revision a048dc4662f1eb83e4e8cd127790473f01470263) @@ -19,11 +19,10 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System.Collections.Generic; using System.Windows.Forms; using Ringtoets.Common.Data.FailureMechanism; -using Ringtoets.Common.Forms.Properties; using Ringtoets.Common.Forms.Views; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.Integration.Forms.Views { @@ -38,51 +37,31 @@ /// public CustomProbabilityFailureMechanismResultView() { - AddCellFormattingHandler(OnCellFormatting); + DataGridViewControl.AddCellFormattingHandler(OnCellFormatting); } private void OnCellFormatting(object sender, DataGridViewCellFormattingEventArgs eventArgs) { if (eventArgs.ColumnIndex > 1) { - if (HasPassedLevelZero(eventArgs.RowIndex)) + if (HasPassedLevelOne(eventArgs.RowIndex)) { - DisableCell(eventArgs.RowIndex, eventArgs.ColumnIndex); + DataGridViewControl.DisableCell(eventArgs.RowIndex, eventArgs.ColumnIndex); } else { - RestoreCell(eventArgs.RowIndex, eventArgs.ColumnIndex); + DataGridViewControl.RestoreCell(eventArgs.RowIndex, eventArgs.ColumnIndex); } } } - protected override IEnumerable GetDataGridColumns() + protected override void AddDataGridColumns() { - foreach (var baseColumn in base.GetDataGridColumns()) - { - yield return baseColumn; - } + base.AddDataGridColumns(); - yield return new DataGridViewTextBoxColumn - { - DataPropertyName = "AssessmentLayerTwoA", - HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_a, - Name = "column_AssessmentLayerTwoA" - }; - - yield return new DataGridViewTextBoxColumn - { - DataPropertyName = "AssessmentLayerTwoB", - HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_b, - Name = "column_AssessmentLayerTwoB" - }; - - yield return new DataGridViewTextBoxColumn - { - DataPropertyName = "AssessmentLayerThree", - HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_three, - Name = "column_AssessmentLayerThree" - }; + DataGridViewControl.AddTextBoxColumn("AssessmentLayerTwoA", RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_a); + DataGridViewControl.AddTextBoxColumn("AssessmentLayerTwoB", RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_b); + DataGridViewControl.AddTextBoxColumn("AssessmentLayerThree", RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_three); } protected override object CreateFailureMechanismSectionResultRow(CustomProbabilityFailureMechanismSectionResult sectionResult) Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/SimpleFailureMechanismResultView.cs =================================================================== diff -u -r2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f -ra048dc4662f1eb83e4e8cd127790473f01470263 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/SimpleFailureMechanismResultView.cs (.../SimpleFailureMechanismResultView.cs) (revision 2fca3f7ae1037eaa9c355b64d7cd0c390143ea8f) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/SimpleFailureMechanismResultView.cs (.../SimpleFailureMechanismResultView.cs) (revision a048dc4662f1eb83e4e8cd127790473f01470263) @@ -1,11 +1,32 @@ -using System; +// Copyright (C) Stichting Deltares 2016. 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 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 General Public License for more details. +// +// You should have received a copy of the GNU 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.Linq; using System.Windows.Forms; using Core.Common.Utils; using Ringtoets.Common.Data.FailureMechanism; -using Ringtoets.Common.Forms.Properties; using Ringtoets.Common.Forms.Views; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.Integration.Forms.Views { @@ -20,57 +41,37 @@ /// public SimpleFailureMechanismResultView() { - AddCellFormattingHandler(OnCellFormatting); + DataGridViewControl.AddCellFormattingHandler(OnCellFormatting); } private void OnCellFormatting(object sender, DataGridViewCellFormattingEventArgs eventArgs) { if (eventArgs.ColumnIndex > 1) { - if (HasPassedLevelZero(eventArgs.RowIndex)) + if (HasPassedLevelOne(eventArgs.RowIndex)) { - DisableCell(eventArgs.RowIndex, eventArgs.ColumnIndex); + DataGridViewControl.DisableCell(eventArgs.RowIndex, eventArgs.ColumnIndex); } else { - RestoreCell(eventArgs.RowIndex, eventArgs.ColumnIndex); + DataGridViewControl.RestoreCell(eventArgs.RowIndex, eventArgs.ColumnIndex); } } } - protected override IEnumerable GetDataGridColumns() + protected override void AddDataGridColumns() { - foreach (var baseColumn in base.GetDataGridColumns()) - { - yield return baseColumn; - } + base.AddDataGridColumns(); - yield return new DataGridViewComboBoxColumn - { - DataPropertyName = "AssessmentLayerTwoA", - HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_a, - Name = "column_AssessmentLayerTwoA", - DataSource = Enum.GetValues(typeof(AssessmentLayerTwoAResult)) - .OfType() - .Select(el => new EnumDisplayWrapper(el)) - .ToList(), - ValueMember = "Value", - DisplayMember = "DisplayName" - }; + var dataSource = Enum.GetValues(typeof(AssessmentLayerTwoAResult)) + .OfType() + .Select(el => new EnumDisplayWrapper(el)) + .Cast() + .ToList(); - yield return new DataGridViewTextBoxColumn - { - DataPropertyName = "AssessmentLayerTwoB", - HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_b, - Name = "column_AssessmentLayerTwoB" - }; - - yield return new DataGridViewTextBoxColumn - { - DataPropertyName = "AssessmentLayerThree", - HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_three, - Name = "column_AssessmentLayerThree" - }; + DataGridViewControl.AddComboBoxColumn("AssessmentLayerTwoA", RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_a, dataSource); + DataGridViewControl.AddTextBoxColumn("AssessmentLayerTwoB", RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_b); + DataGridViewControl.AddTextBoxColumn("AssessmentLayerThree", RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_three); } protected override object CreateFailureMechanismSectionResultRow(SimpleFailureMechanismSectionResult sectionResult) Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismResultView.cs =================================================================== diff -u -ra883652e0cf7e59e4d086472939379ad9be36472 -ra048dc4662f1eb83e4e8cd127790473f01470263 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismResultView.cs (.../PipingFailureMechanismResultView.cs) (revision a883652e0cf7e59e4d086472939379ad9be36472) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingFailureMechanismResultView.cs (.../PipingFailureMechanismResultView.cs) (revision a048dc4662f1eb83e4e8cd127790473f01470263) @@ -20,7 +20,6 @@ // All rights reserved. using System; -using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using Core.Common.Base; @@ -31,6 +30,7 @@ using Ringtoets.Piping.Data; using CoreCommonResources = Core.Common.Base.Properties.Resources; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.Piping.Forms.Views { @@ -51,8 +51,8 @@ /// public PipingFailureMechanismResultView() { - AddCellFormattingHandler(ShowAssementLayerTwoAErrors); - AddCellFormattingHandler(DisableIrrelevantFieldsFormatting); + DataGridViewControl.AddCellFormattingHandler(ShowAssementLayerTwoAErrors); + DataGridViewControl.AddCellFormattingHandler(DisableIrrelevantFieldsFormatting); // The concat is needed to observe the input of calculations in child groups. calculationInputObserver = new RecursiveObserver(UpdataDataGridViewDataSource, cg => cg.Children.Concat(cg.Children.OfType().Select(c => c.GetObservableInput()))); @@ -84,34 +84,13 @@ base.Dispose(disposing); } - protected override IEnumerable GetDataGridColumns() + protected override void AddDataGridColumns() { - foreach (var baseColumn in base.GetDataGridColumns()) - { - yield return baseColumn; - } + base.AddDataGridColumns(); - yield return new DataGridViewTextBoxColumn - { - DataPropertyName = "AssessmentLayerTwoA", - HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_a, - Name = "column_AssessmentLayerTwoA", - ReadOnly = true - }; - - yield return new DataGridViewTextBoxColumn - { - DataPropertyName = "AssessmentLayerTwoB", - HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_b, - Name = "column_AssessmentLayerTwoB" - }; - - yield return new DataGridViewTextBoxColumn - { - DataPropertyName = "AssessmentLayerThree", - HeaderText = Resources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_three, - Name = "column_AssessmentLayerThree" - }; + DataGridViewControl.AddTextBoxColumn("AssessmentLayerTwoA", RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_a, true); + DataGridViewControl.AddTextBoxColumn("AssessmentLayerTwoB", RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_two_b); + DataGridViewControl.AddTextBoxColumn("AssessmentLayerThree", RingtoetsCommonFormsResources.FailureMechanismResultView_InitializeDataGridView_Assessment_layer_three); } protected override object CreateFailureMechanismSectionResultRow(PipingFailureMechanismSectionResult sectionResult) @@ -125,20 +104,20 @@ { if (eventArgs.ColumnIndex > 1) { - if (HasPassedLevelZero(eventArgs.RowIndex)) + if (HasPassedLevelOne(eventArgs.RowIndex)) { - DisableCell(eventArgs.RowIndex, eventArgs.ColumnIndex); + DataGridViewControl.DisableCell(eventArgs.RowIndex, eventArgs.ColumnIndex); } else { - RestoreCell(eventArgs.RowIndex, eventArgs.ColumnIndex); + DataGridViewControl.RestoreCell(eventArgs.RowIndex, eventArgs.ColumnIndex, eventArgs.ColumnIndex == assessmentLayerTwoAIndex); } } } private void ShowAssementLayerTwoAErrors(object sender, DataGridViewCellFormattingEventArgs e) { - var currentDataGridViewCell = GetCell(e.RowIndex, e.ColumnIndex); + var currentDataGridViewCell = DataGridViewControl.GetCell(e.RowIndex, e.ColumnIndex); PipingFailureMechanismSectionResultRow resultRow = (PipingFailureMechanismSectionResultRow) GetDataAtRow(e.RowIndex);