2009-01-02 Ivan N. Zlatev <contact@i-nz.net>
authorIvan Zlatev <ivan@ivanz.com>
Thu, 1 Jan 2009 23:02:41 +0000 (23:02 -0000)
committerIvan Zlatev <ivan@ivanz.com>
Thu, 1 Jan 2009 23:02:41 +0000 (23:02 -0000)
* DataGridViewCellCollection.cs: When cells are removed the column
indices become invalid if the cell is not the last one and have to
be refreshed.

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

mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewCellCollection.cs

index 6192d93d817978857eafd196fdb376a9ff1d6092..b286c197e26580f2324e30158675a8f539354d16 100644 (file)
@@ -183,6 +183,7 @@ namespace System.Windows.Forms
                public virtual void Remove (DataGridViewCell cell)
                {
                        base.List.Remove (cell);
+                       ReIndex ();
                        OnCollectionChanged (new CollectionChangeEventArgs (
                                CollectionChangeAction.Remove, cell));
                }
@@ -191,10 +192,17 @@ namespace System.Windows.Forms
                {
                        DataGridViewCell cell = this [index];
                        base.List.RemoveAt (index);
+                       ReIndex ();
                        OnCollectionChanged (new CollectionChangeEventArgs (
                                CollectionChangeAction.Remove, cell));
                }
 
+               private void ReIndex ()
+               {
+                       for (int i = 0; i < base.List.Count; i++)
+                               this[i].SetColumnIndex (i);
+               }
+
                protected override ArrayList List {
                        get { return base.List; }
                }