2009-03-19 Ivan N. Zlatev <contact@i-nz.net>
authorIvan Zlatev <ivan@ivanz.com>
Thu, 19 Mar 2009 18:09:38 +0000 (18:09 -0000)
committerIvan Zlatev <ivan@ivanz.com>
Thu, 19 Mar 2009 18:09:38 +0000 (18:09 -0000)
* DataGridView.cs, DataGridViewCellCollection.cs: Split the column removal
to perform Pre and Post removal actions to allow the current cell to be
moved and all events fired properly before the column is removed.

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

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/DataGridViewColumnCollection.cs

index 62d5e968dac70184ed653f014bf90c7f60e4774d..9532c18b13b08db15d5c47d84c52ac90a3609b70 100644 (file)
@@ -1,3 +1,9 @@
+2009-03-19  Ivan N. Zlatev  <contact@i-nz.net>
+
+       * DataGridView.cs, DataGridViewCellCollection.cs: Split the column removal 
+       to perform Pre and Post removal actions to allow the current cell to be 
+       moved and all events fired properly before the column is removed.
+
 2009-03-19  Ivan N. Zlatev  <contact@i-nz.net>
 
        * DataGridView.cs, DataGridViewRow.cs: Split the row removal to perform Pre and 
index 7a0d8d52e5701ab8c658dbe2a23c3f9ba02e65ea..ffc8bd7c59bb40ab80fcce63b852beef786d78b8 100644 (file)
@@ -3848,7 +3848,22 @@ namespace System.Windows.Forms {
                                eh (this, e);
                }
 
-               internal void OnColumnRemovedInternal (DataGridViewColumnEventArgs e)
+               internal void OnColumnPreRemovedInternal (DataGridViewColumnEventArgs e)
+               {
+                       if (Columns.Count - 1 == 0) {
+                               MoveCurrentCell (-1, -1, true, false, false, true);
+                               rows.ClearInternal ();
+                       } else if (currentCell != null && CurrentCell.ColumnIndex == e.Column.Index) {
+                               int nextColumnIndex = e.Column.Index;
+                               if (nextColumnIndex >= Columns.Count - 1)
+                                       nextColumnIndex = Columns.Count - 1 - 1;
+                               MoveCurrentCell (nextColumnIndex, currentCell.RowIndex, true, false, false, true);
+                               if (hover_cell != null && hover_cell.ColumnIndex >= e.Column.Index)
+                                       hover_cell = null;
+                       }
+               }
+
+               private void OnColumnPostRemovedInternal (DataGridViewColumnEventArgs e)
                {
                        if (e.Column.CellTemplate != null) {
                                int index = e.Column.Index;
@@ -3859,17 +3874,6 @@ namespace System.Windows.Forms {
 
                        AutoResizeColumnsInternal ();
                        PrepareEditingRow (false, true);
-                       if (Columns.Count == 0) {
-                               rows.ClearInternal ();
-                               MoveCurrentCell (-1, -1, true, false, false, true);
-                       } else if (currentCell != null && CurrentCell.ColumnIndex == e.Column.Index) {
-                               int nextColumnIndex = e.Column.Index;
-                               if (nextColumnIndex >= Columns.Count)
-                                       nextColumnIndex = Columns.Count - 1;
-                               MoveCurrentCell (nextColumnIndex, currentCell.RowIndex, true, false, false, true);
-                               if (hover_cell != null && hover_cell.ColumnIndex >= e.Column.Index)
-                                       hover_cell = null;
-                       }
 
                        OnColumnRemoved (e);
                }
@@ -5696,7 +5700,7 @@ namespace System.Windows.Forms {
                                        OnColumnAddedInternal(new DataGridViewColumnEventArgs(e.Element as DataGridViewColumn));
                                        break;
                                case CollectionChangeAction.Remove:
-                                       OnColumnRemovedInternal(new DataGridViewColumnEventArgs(e.Element as DataGridViewColumn));
+                                       OnColumnPostRemovedInternal(new DataGridViewColumnEventArgs(e.Element as DataGridViewColumn));
                                        break;
                                case CollectionChangeAction.Refresh:
                                        break;
index c5bbd9c4d6bb280e15b2aa0d1135bf729cf97239..f2242dd5788a9982ea8e882a48b2451229a57757 100644 (file)
@@ -198,6 +198,7 @@ namespace System.Windows.Forms
 
                public virtual void Remove (DataGridViewColumn dataGridViewColumn)
                {
+                       DataGridView.OnColumnPreRemovedInternal (new DataGridViewColumnEventArgs (dataGridViewColumn));
                        base.List.Remove (dataGridViewColumn);
                        OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, dataGridViewColumn));
                }