Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuriy <32514157+YuriyGS@users.noreply.github.com>2017-11-03 22:46:25 +0300
committerAlexander Köplinger <alex.koeplinger@outlook.com>2017-11-03 22:46:25 +0300
commitc43d73cfd746df2e8937b7bc43d0b95ca8b02c6b (patch)
treef91b7dd5625ec75495eba0eb885dbdb1e0528775 /mcs/class/System.Windows.Forms
parent151fa5590f9eea8aefe5981c3b899d7071630a14 (diff)
[System.Windows.Forms] Fixes #60435. DataGridViewRow.CreateCellsInstance method is never invoked
This fixes bug #60435, where the DataGridViewRow.CreateCellsInstance method is never invoked. Now value of the Cells property is initialized by calling the CreateCellsInstance method.
Diffstat (limited to 'mcs/class/System.Windows.Forms')
-rw-r--r--mcs/class/System.Windows.Forms/System.Windows.Forms/DataGridViewRow.cs31
-rw-r--r--mcs/class/System.Windows.Forms/Test/System.Windows.Forms/DataGridViewRowTest.cs23
2 files changed, 39 insertions, 15 deletions
diff --git a/mcs/class/System.Windows.Forms/System.Windows.Forms/DataGridViewRow.cs b/mcs/class/System.Windows.Forms/System.Windows.Forms/DataGridViewRow.cs
index 8130f70df0a..300ed426ec8 100644
--- a/mcs/class/System.Windows.Forms/System.Windows.Forms/DataGridViewRow.cs
+++ b/mcs/class/System.Windows.Forms/System.Windows.Forms/DataGridViewRow.cs
@@ -46,7 +46,6 @@ namespace System.Windows.Forms
public DataGridViewRow ()
{
- cells = new DataGridViewCellCollection(this);
minimumHeight = 3;
height = -1;
explicit_height = -1;
@@ -64,7 +63,11 @@ namespace System.Windows.Forms
[Browsable (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
public DataGridViewCellCollection Cells {
- get { return cells; }
+ get {
+ if (cells == null)
+ cells = CreateCellsInstance ();
+ return cells;
+ }
}
[DefaultValue (null)]
@@ -356,10 +359,10 @@ namespace System.Windows.Forms
row.HeaderCell = (DataGridViewRowHeaderCell)HeaderCell.Clone ();
row.SetIndex (-1);
- row.cells = new DataGridViewCellCollection (row);
+ row.cells = null;
- foreach (DataGridViewCell cell in cells)
- row.cells.Add (cell.Clone () as DataGridViewCell);
+ foreach (DataGridViewCell cell in Cells)
+ row.Cells.Add (cell.Clone () as DataGridViewCell);
row.SetDataGridView (null);
@@ -374,14 +377,13 @@ namespace System.Windows.Forms
if (dataGridView.Rows.Contains(this)) {
throw new InvalidOperationException("The row already exists in the DataGridView.");
}
- DataGridViewCellCollection newCellCollection = new DataGridViewCellCollection(this);
+ Cells.Clear ();
foreach (DataGridViewColumn column in dataGridView.Columns) {
if (column.CellTemplate == null) {
throw new InvalidOperationException("Cell template not set in column: " + column.Index.ToString() + ".");
}
- newCellCollection.Add((DataGridViewCell) column.CellTemplate.Clone());
+ Cells.Add((DataGridViewCell) column.CellTemplate.Clone());
}
- cells = newCellCollection;
}
public void CreateCells (DataGridView dataGridView, params object[] values)
@@ -391,7 +393,7 @@ namespace System.Windows.Forms
}
CreateCells(dataGridView);
for (int i = 0; i < values.Length; i++) {
- cells[i].Value = values[i];
+ Cells[i].Value = values[i];
}
}
@@ -482,11 +484,11 @@ namespace System.Windows.Forms
/////// COLUMNAS //////////
for (int i = 0; i < values.Length; i++) {
DataGridViewCell cell;
- if (cells.Count > i) {
- cell = cells [i];
+ if (Cells.Count > i) {
+ cell = Cells [i];
} else {
cell = new DataGridViewTextBoxCell ();
- cells.Add (cell);
+ Cells.Add (cell);
}
cell.Value = values[i];
}
@@ -508,8 +510,7 @@ namespace System.Windows.Forms
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected virtual DataGridViewCellCollection CreateCellsInstance ()
{
- cells = new DataGridViewCellCollection(this);
- return cells;
+ return new DataGridViewCellCollection(this);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
@@ -614,7 +615,7 @@ namespace System.Windows.Forms
{
base.SetDataGridView(dataGridView);
headerCell.SetDataGridView(dataGridView);
- foreach (DataGridViewCell cell in cells)
+ foreach (DataGridViewCell cell in Cells)
cell.SetDataGridView (dataGridView);
}
diff --git a/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/DataGridViewRowTest.cs b/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/DataGridViewRowTest.cs
index a6f0ad48b01..a79d7744131 100644
--- a/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/DataGridViewRowTest.cs
+++ b/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/DataGridViewRowTest.cs
@@ -408,5 +408,28 @@ namespace MonoTests.System.Windows.Forms {
Assert.AreEqual ("Helo", row2.Tag, "A8");
Assert.AreEqual (false, row2.Visible, "A9");
}
+
+
+ private class TestDataGridViewRow : DataGridViewRow
+ {
+ protected override DataGridViewCellCollection CreateCellsInstance ()
+ {
+ return new MockDataGridViewCellCollection (this);
+ }
+ }
+
+ private class MockDataGridViewCellCollection : DataGridViewCellCollection
+ {
+ public MockDataGridViewCellCollection(DataGridViewRow dataGridViewRow) : base(dataGridViewRow)
+ {
+ }
+ }
+
+ [Test]
+ public void CreateCellsInstance ()
+ {
+ var row = new TestDataGridViewRow ();
+ Assert.That (row.Cells, Is.TypeOf<MockDataGridViewCellCollection> (), "#A row.CreateCellsInstance");
+ }
}
}