Index: Core/Common/src/Core.Common.Controls/DataGrid/DataGridViewControl.cs
===================================================================
diff -u -rac1e7b044016869e0c2b7668171c0dbfe0be1788 -rd48d2c62b4a2d2f177e1725e1b84e54a8d49327f
--- Core/Common/src/Core.Common.Controls/DataGrid/DataGridViewControl.cs (.../DataGridViewControl.cs) (revision ac1e7b044016869e0c2b7668171c0dbfe0be1788)
+++ Core/Common/src/Core.Common.Controls/DataGrid/DataGridViewControl.cs (.../DataGridViewControl.cs) (revision d48d2c62b4a2d2f177e1725e1b84e54a8d49327f)
@@ -44,6 +44,18 @@
}
///
+ /// Returns true when the is in edit mode.
+ /// False otherwise.
+ ///
+ public bool IsCurrentCellInEditMode
+ {
+ get
+ {
+ return dataGridView.IsCurrentCellInEditMode;
+ }
+ }
+
+ ///
/// Adds a new to the with the given data.
///
/// The of the column.
@@ -135,6 +147,14 @@
}
///
+ /// Adjusts the width of all columns to fit the contents of all their cells, including the header cells.
+ ///
+ public void AutoResizeColumns()
+ {
+ dataGridView.AutoResizeColumns();
+ }
+
+ ///
/// Ends the editing when the current cell is in edit mode.
/// Sets the current cell to null.
///
@@ -149,6 +169,15 @@
}
///
+ /// Gets all the rows of the .
+ ///
+ /// A with all the rows of the .
+ public DataGridViewRowCollection GetRows()
+ {
+ return dataGridView.Rows;
+ }
+
+ ///
/// Gets the on the given index.
///
/// The index of the row.
@@ -160,6 +189,16 @@
}
///
+ /// Gets the row containing the current cell.
+ ///
+ /// The that represents the row containing the current cell,
+ /// or null if there is no current cell.
+ public DataGridViewRow GetCurrentRow()
+ {
+ return dataGridView.CurrentRow;
+ }
+
+ ///
/// Gets the on the given row and column index.
///
/// The index of the row the cell is on.
@@ -171,6 +210,17 @@
return GetRowFromIndex(rowIndex).Cells[columnIndex];
}
+ ///
+ /// Gets the on the given index.
+ ///
+ /// The index of the column.
+ /// A .
+ /// Thrown when the index of the column does not exist.
+ public DataGridViewColumn GetColumnFromIndex(int columnIndex)
+ {
+ return dataGridView.Columns[columnIndex];
+ }
+
#region Styling
///
@@ -218,6 +268,15 @@
dataGridView.CellFormatting += handler;
}
+ ///
+ /// Add a handler for the event.
+ ///
+ /// The handler to add.
+ public void AddCellClickHandler(DataGridViewCellEventHandler handler)
+ {
+ dataGridView.CellClick += handler;
+ }
+
private void SubscribeEvents()
{
dataGridView.CurrentCellDirtyStateChanged += DataGridViewOnCurrentCellDirtyStateChanged;
Index: Core/Common/test/Core.Common.Controls.Test/DataGrid/DataGridViewControlTest.cs
===================================================================
diff -u -r5341ef6e47326ef870d7e6f918c9085d7073d3c9 -rd48d2c62b4a2d2f177e1725e1b84e54a8d49327f
--- Core/Common/test/Core.Common.Controls.Test/DataGrid/DataGridViewControlTest.cs (.../DataGridViewControlTest.cs) (revision 5341ef6e47326ef870d7e6f918c9085d7073d3c9)
+++ Core/Common/test/Core.Common.Controls.Test/DataGrid/DataGridViewControlTest.cs (.../DataGridViewControlTest.cs) (revision d48d2c62b4a2d2f177e1725e1b84e54a8d49327f)
@@ -81,6 +81,69 @@
}
[Test]
+ public void IsCurrentCellInEditMode_CurrentCellInEditMode_ReturnsTrue()
+ {
+ // 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);
+
+ // Call
+ bool editMode = control.IsCurrentCellInEditMode;
+
+ // Assert
+ Assert.IsTrue(editMode);
+ }
+ }
+
+ [Test]
+ public void IsCurrentCellInEditMode_CurrentCellNotInEditMode_ReturnsFalse()
+ {
+ // 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;
+
+ // Call
+ bool editMode = control.IsCurrentCellInEditMode;
+
+ // Assert
+ Assert.IsFalse(editMode);
+ }
+ }
+
+ [Test]
[TestCase(true)]
[TestCase(false)]
public void AddTextBoxColumn_Always_AddsColumnToDataGridView(bool readOnly)
@@ -283,6 +346,31 @@
}
[Test]
+ public void GetRows_Always_ReturnsAllDataGridViewRows()
+ {
+ // 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[] { "Row 1", "Row 2" };
+
+ // Call
+ DataGridViewRowCollection rows = control.GetRows();
+
+ // Assert
+ Assert.AreEqual(2, rows.Count);
+ }
+ }
+
+ [Test]
public void GetRowFromIndex_RowDoesExist_ReturnsRow()
{
// Setup
@@ -333,6 +421,59 @@
}
[Test]
+ public void GetCurrentRow_CurrentCellSet_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[] { "" };
+ var dataGridViewCell = dataGridView.Rows[0].Cells[0];
+ dataGridView.CurrentCell = dataGridViewCell;
+
+ // Call
+ DataGridViewRow row = control.GetCurrentRow();
+
+ // Assert
+ Assert.IsNotNull(row);
+ }
+ }
+
+ [Test]
+ public void GetCurrentRow_CurrentCellNotSet_ReturnsNull()
+ {
+ // 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[] { "" };
+ dataGridView.CurrentCell = null;
+
+ // Call
+ DataGridViewRow row = control.GetCurrentRow();
+
+ // Assert
+ Assert.IsNull(row);
+ }
+ }
+
+ [Test]
public void GetCell_RowAndCellDoesExist_ReturnsCell()
{
// Setup
@@ -408,6 +549,60 @@
}
[Test]
+ public void GetColumnFromIndex_ColumnDoesExist_ReturnsColumn()
+ {
+ // 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;
+
+ var dataPropertyName = "Test property";
+ var testHeader = "Test header";
+ control.AddTextBoxColumn(dataPropertyName, testHeader);
+
+ dataGridView.DataSource = new[] { "" };
+
+ // Call
+ DataGridViewColumn column = control.GetColumnFromIndex(0);
+
+ // Assert
+ Assert.IsNotNull(column);
+ Assert.AreEqual(dataPropertyName, column.DataPropertyName);
+ Assert.AreEqual(testHeader, column.HeaderText);
+ }
+ }
+
+ [Test]
+ public void GetColumnFromIndex_ColumnDoesNotExist_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.GetColumnFromIndex(5);
+
+ // Assert
+ Assert.Throws(call);
+ }
+ }
+
+ [Test]
public void DisableCell_Always_DisablesCell()
{
// Setup
@@ -542,6 +737,40 @@
}
[Test]
+ public void AddCellClickHandler_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.AddCellClickHandler((sender, args) => counter++);
+
+ // Precondition
+ Assert.AreEqual(0, counter);
+
+ // Call
+ gridTester.FireEvent("CellClick", new DataGridViewCellEventArgs(0, 0));
+
+ // Assert
+ Assert.AreEqual(1, counter);
+ }
+ }
+
+ [Test]
public void DataGridViewControlCheckBoxColumn_EditValueDirtyStateChangedEventFired_ValueCommittedCellInEditMode()
{
// Setup
Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingCalculationsView.Designer.cs
===================================================================
diff -u -r7b59ab6aaa9f81445151848d8b3aa651062ee6b7 -rd48d2c62b4a2d2f177e1725e1b84e54a8d49327f
--- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingCalculationsView.Designer.cs (.../PipingCalculationsView.Designer.cs) (revision 7b59ab6aaa9f81445151848d8b3aa651062ee6b7)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingCalculationsView.Designer.cs (.../PipingCalculationsView.Designer.cs) (revision d48d2c62b4a2d2f177e1725e1b84e54a8d49327f)
@@ -23,18 +23,17 @@
this.labelFailureMechanismSections = new System.Windows.Forms.Label();
this.tableLayoutPanelDataGrid = new System.Windows.Forms.TableLayoutPanel();
this.labelCalculations = new System.Windows.Forms.Label();
- this.dataGridView = new System.Windows.Forms.DataGridView();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.buttonGenerateScenarios = new System.Windows.Forms.Button();
this.buttonNavigateToSelectedCalculation = new System.Windows.Forms.Button();
+ this.dataGridViewControl = new Core.Common.Controls.DataGrid.DataGridViewControl();
this.tableLayoutPanelUserControl.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
this.splitContainer.Panel1.SuspendLayout();
this.splitContainer.Panel2.SuspendLayout();
this.splitContainer.SuspendLayout();
this.tableLayoutPanelListBox.SuspendLayout();
this.tableLayoutPanelDataGrid.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.tableLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
@@ -81,27 +80,14 @@
//
resources.ApplyResources(this.tableLayoutPanelDataGrid, "tableLayoutPanelDataGrid");
this.tableLayoutPanelDataGrid.Controls.Add(this.labelCalculations, 0, 0);
- this.tableLayoutPanelDataGrid.Controls.Add(this.dataGridView, 0, 1);
+ this.tableLayoutPanelDataGrid.Controls.Add(this.dataGridViewControl, 0, 1);
this.tableLayoutPanelDataGrid.Name = "tableLayoutPanelDataGrid";
//
// labelCalculations
//
resources.ApplyResources(this.labelCalculations, "labelCalculations");
this.labelCalculations.Name = "labelCalculations";
//
- // dataGridView
- //
- this.dataGridView.AllowUserToAddRows = false;
- this.dataGridView.AllowUserToDeleteRows = false;
- this.dataGridView.AllowUserToResizeColumns = false;
- this.dataGridView.AllowUserToResizeRows = false;
- this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader;
- this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
- resources.ApplyResources(this.dataGridView, "dataGridView");
- this.dataGridView.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter;
- this.dataGridView.Name = "dataGridView";
- this.dataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing;
- //
// tableLayoutPanel1
//
resources.ApplyResources(this.tableLayoutPanel1, "tableLayoutPanel1");
@@ -122,6 +108,11 @@
this.buttonNavigateToSelectedCalculation.Name = "buttonNavigateToSelectedCalculation";
this.buttonNavigateToSelectedCalculation.UseVisualStyleBackColor = true;
//
+ // dataGridViewControl
+ //
+ resources.ApplyResources(this.dataGridViewControl, "dataGridViewControl");
+ this.dataGridViewControl.Name = "dataGridViewControl";
+ //
// PipingCalculationsView
//
resources.ApplyResources(this, "$this");
@@ -137,7 +128,6 @@
this.tableLayoutPanelListBox.PerformLayout();
this.tableLayoutPanelDataGrid.ResumeLayout(false);
this.tableLayoutPanelDataGrid.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.tableLayoutPanel1.ResumeLayout(false);
this.ResumeLayout(false);
@@ -152,9 +142,9 @@
private System.Windows.Forms.Label labelFailureMechanismSections;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanelDataGrid;
private System.Windows.Forms.Label labelCalculations;
- private System.Windows.Forms.DataGridView dataGridView;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.Button buttonGenerateScenarios;
private System.Windows.Forms.Button buttonNavigateToSelectedCalculation;
+ private Core.Common.Controls.DataGrid.DataGridViewControl dataGridViewControl;
}
}
Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingCalculationsView.cs
===================================================================
diff -u -r0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3 -rd48d2c62b4a2d2f177e1725e1b84e54a8d49327f
--- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingCalculationsView.cs (.../PipingCalculationsView.cs) (revision 0d1a1a5d6962e334a56ec7fd0c83488c6f377ca3)
+++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingCalculationsView.cs (.../PipingCalculationsView.cs) (revision d48d2c62b4a2d2f177e1725e1b84e54a8d49327f)
@@ -55,11 +55,13 @@
private readonly Observer pipingFailureMechanismObserver;
private readonly Observer pipingStochasticSoilModelsObserver;
private IAssessmentSection assessmentSection;
- private DataGridViewComboBoxColumn hydraulicBoundaryLocationColumn;
private CalculationGroup calculationGroup;
private PipingFailureMechanism pipingFailureMechanism;
- private DataGridViewComboBoxColumn stochasticSoilModelColumn;
- private DataGridViewComboBoxColumn stochasticSoilProfileColumn;
+
+ private const int stochasticSoilModelColumnIndex = 3;
+ private const int stochasticSoilProfileColumnIndex = 4;
+ private const int hydraulicBoundaryLocationColumnIndex = 6;
+
private bool updatingDataSource;
///
@@ -77,7 +79,7 @@
// The concat is needed to observe the input of calculations in child groups.
pipingInputObserver = new RecursiveObserver(UpdateDataGridViewDataSource, pcg => pcg.Children.Concat