https://bugzilla.xamarin.com/show_bug.cgi?id=3125
authorsesef <sesef@sesef.pl>
Thu, 2 Aug 2012 20:17:16 +0000 (22:17 +0200)
committersesef <sesef@sesef.pl>
Thu, 2 Aug 2012 20:17:16 +0000 (22:17 +0200)
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewRowCollection.cs
mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/DataGridViewTest.cs

index 4937414cc7549c10928d6ab3e90089c5e688485c..cbd8c2a574eeed748c1ef6daa74b43036e0ae433 100644 (file)
@@ -265,7 +265,8 @@ namespace System.Windows.Forms
                                // We can exit because the NewRow is always last
                                if (row.IsNewRow)
                                        break;
-                                       
+
+                row.SetDataGridView(null);
                                list.Remove (row);
                                ReIndex ();
                        }
@@ -485,6 +486,7 @@ namespace System.Windows.Forms
                                throw new InvalidOperationException ("Cannot delete the new row");
                                
                        DataGridView.OnRowsPreRemovedInternal (new DataGridViewRowsRemovedEventArgs (dataGridViewRow.Index, 1));
+            dataGridViewRow.SetDataGridView(null);
                        list.Remove (dataGridViewRow);
                        ReIndex ();
                        OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, dataGridViewRow));
@@ -494,6 +496,7 @@ namespace System.Windows.Forms
                internal virtual void RemoveInternal (DataGridViewRow dataGridViewRow)
                {
                        DataGridView.OnRowsPreRemovedInternal (new DataGridViewRowsRemovedEventArgs (dataGridViewRow.Index, 1));
+            dataGridViewRow.SetDataGridView(null);
                        list.Remove (dataGridViewRow);
                        ReIndex ();
                        OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, dataGridViewRow));
index ce0b32c9ca0f4e9f61505f4c2d87f079a61977e2..b9e06b1abc1208b1ab95576e2abbbfa87fe6da63 100644 (file)
@@ -2463,6 +2463,29 @@ namespace MonoTests.System.Windows.Forms
                        catch (ArgumentOutOfRangeException) {
                        }
                }
+
+        [Test] // Xamarin bug 3125
+        public void TestRemoveBug3125()
+        {
+            DataGridViewRow dgvr1 = new DataGridViewRow();
+            DataGridViewRow dgvr2 = new DataGridViewRow();
+            DataGridViewRow dgvr3 = new DataGridViewRow();
+
+            Assert.IsNull (dgvr1.DataGridView, "#1");
+            Assert.IsNull (dgvr2.DataGridView, "#2");
+            Assert.IsNull (dgvr3.DataGridView, "#3");
+
+            DataGridView dgv = new DataGridView();
+            dgv.Rows.Add(dgvr1);
+            dgv.Rows.Add(dgvr2);
+            dgv.Rows.Add(dgvr3);
+
+            dgv.Clear();
+
+            Assert.IsNull(dgvr1.DataGridView, "#4");
+            Assert.IsNull(dgvr2.DataGridView, "#5");
+            Assert.IsNull(dgvr3.DataGridView, "#6");
+        }
        }
        
        [TestFixture]