2009-02-03 Ivan N. Zlatev <contact@i-nz.net>
authorIvan Zlatev <ivan@ivanz.com>
Tue, 3 Feb 2009 19:39:22 +0000 (19:39 -0000)
committerIvan Zlatev <ivan@ivanz.com>
Tue, 3 Feb 2009 19:39:22 +0000 (19:39 -0000)
* DataGridViewRowCollection.cs, DataGridView.cs: Move row completion
code in the row collection code, so that the completion happens before
the CollectionChanged event, also better encapsulation.
[Fixes bug #471987]

svn path=/trunk/mcs/; revision=125585

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewRowCollection.cs

index 14d5ba4f67d119e3b5a5589736715a2d132d6ff4..508538d449c407f89d918983a4cd6a41ee746dfd 100644 (file)
@@ -1,3 +1,10 @@
+2009-02-03  Ivan N. Zlatev  <contact@i-nz.net>
+
+       * DataGridViewRowCollection.cs, DataGridView.cs: Move row completion 
+       code in the row collection code, so that the completion happens before 
+       the CollectionChanged event, also better encapsulation.
+       [Fixes bug #471987]
+
 2009-02-02  Ivan N. Zlatev  <contact@i-nz.net>
 
        * DataGridView.cs: When editing is finished do not remove the editing 
index 281f3006dc12acbaa6da5194dd5e69858c4c17df..fa23e0b34d2b018c9c154cb590ee5f763c1cf06a 100644 (file)
@@ -4831,14 +4831,6 @@ namespace System.Windows.Forms {
                        if (hover_cell != null && hover_cell.RowIndex >= e.RowIndex)
                                hover_cell = null;
 
-                       // Complete the rows if they are incomplete.
-                       for (int i = e.RowIndex; i < e.RowIndex + e.RowCount; i++) {
-                               if (Rows[i].Cells.Count < ColumnCount) {
-                                       for (int j = Rows[i].Cells.Count; j < ColumnCount; j++)
-                                               Rows[i].Cells.Add ((DataGridViewCell) columns[j].CellTemplate.Clone ());
-                               }
-                       }
-
                        AutoResizeColumnsInternal ();
                        Invalidate ();
                        OnRowsAdded (e);
index b6cca9df4e77bd4c2e35fc71580a71ac17450406..6445f56ea4c4e754652ca32b9d61671ecc81c1d6 100644 (file)
@@ -135,7 +135,7 @@ namespace System.Windows.Forms
                                dataGridViewRow.SetIndex (result);
                        }
                        dataGridViewRow.SetDataGridView (dataGridView);
-
+                       CompleteRowCells (dataGridViewRow);
                        for (int i = 0; i < dataGridViewRow.Cells.Count; i++) {
                                dataGridViewRow.Cells [i].SetOwningColumn (dataGridView.Columns [i]);
                        }
@@ -147,6 +147,18 @@ namespace System.Windows.Forms
                        return result;
                }
 
+               // Complete the rows if they are incomplete.
+               private void CompleteRowCells (DataGridViewRow row)
+               {
+                       if (row == null || DataGridView == null)
+                               return;
+
+                       if (row.Cells.Count < DataGridView.ColumnCount) {
+                               for (int i = row.Cells.Count; i < DataGridView.ColumnCount; i++)
+                                       row.Cells.Add ((DataGridViewCell) DataGridView.Columns[i].CellTemplate.Clone ());
+                       }
+               }
+
                public virtual int Add (DataGridViewRow dataGridViewRow)
                {
                        if (dataGridView.DataSource != null)
@@ -391,6 +403,7 @@ namespace System.Windows.Forms
                {
                        dataGridViewRow.SetIndex (rowIndex);
                        dataGridViewRow.SetDataGridView (dataGridView);
+                       CompleteRowCells (dataGridViewRow);
                        list[rowIndex] = dataGridViewRow;
                        OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, dataGridViewRow));
                        if (raiseEvent)