2009-03-08 Ivan N. Zlatev <contact@i-nz.net>
authorIvan Zlatev <ivan@ivanz.com>
Sun, 8 Mar 2009 12:48:22 +0000 (12:48 -0000)
committerIvan Zlatev <ivan@ivanz.com>
Sun, 8 Mar 2009 12:48:22 +0000 (12:48 -0000)
* DataGridView.cs: When removing the first displayed row and moving
the current cell up one we must invalidate the first displayed row
index before calculating the row heights, etc.
* DataGridViewTest.cs: Add tests for CurrentCell.
[Fixes bug #483202]

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

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs
mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/DataGridViewTest.cs

index 7162ca91aab43c681225ea86aa58e1d95510097f..cab9ee244efce12d6705d9d0ef2f19fc58876035 100644 (file)
@@ -1,3 +1,10 @@
+2009-03-08  Ivan N. Zlatev  <contact@i-nz.net>
+
+       * DataGridView.cs: When removing the first displayed row and moving 
+       the current cell up one we must invalidate the first displayed row 
+       index before calculating the row heights, etc.
+       [Fixes bug #483202]
+
 2009-03-08  Ivan N. Zlatev  <contact@i-nz.net>
 
        * DataGridView.cs: Fix three column bugs:
index 491177b21dc2b81365f688375d401c700001aaa8..64a6d83c85ee43978c96e66d21a9bba9d2b6f801 100644 (file)
@@ -4897,7 +4897,7 @@ namespace System.Windows.Forms {
                        } else if (Columns.Count == 0) {
                                MoveCurrentCell (-1, -1, true, false, false, true);
                                hover_cell = null;
-                       } else {
+                       } else if (currentCell != null && currentCell.RowIndex == e.RowIndex) {
                                int nextRowIndex = e.RowIndex;
                                if (nextRowIndex >= Rows.Count)
                                        nextRowIndex = Rows.Count - 1;
@@ -6040,9 +6040,13 @@ namespace System.Windows.Forms {
 
                                        if (disp_x == 0)
                                                delta_x = horizontalScrollBar.Value;
-                                       else
+                                       else {
+                                               // in case the column got removed
+                                               if (first_col_index >= ColumnCount)
+                                                       first_col_index = ColumnCount - 1;
                                                for (int i = disp_x; i < first_col_index; i++)
                                                        delta_x += Columns[ColumnDisplayIndexToIndex (i)].Width;
+                                       }
                                
                                        horizontalScrollBar.SafeValueSet (horizontalScrollBar.Value - delta_x);
                                        OnHScrollBarScroll (this, new ScrollEventArgs (ScrollEventType.ThumbPosition, horizontalScrollBar.Value));
@@ -6058,15 +6062,20 @@ namespace System.Windows.Forms {
 
                                        if (disp_y == 0)
                                                delta_y = verticalScrollBar.Value;
-                                       else
+                                       else {
+                                               // in case the row got removed
+                                               if (first_row_index >= RowCount)
+                                                       first_row_index = RowCount - 1;
                                                for (int i = disp_y; i < first_row_index; i++)
                                                        delta_y += GetRowInternal (i).Height;
+                                       }
 
                                        verticalScrollBar.SafeValueSet (verticalScrollBar.Value - delta_y);
                                        OnVScrollBarScroll (this, new ScrollEventArgs (ScrollEventType.ThumbPosition, verticalScrollBar.Value));
                                } else if (disp_y > first_row_index + displayedRowsCount - 1) {
                                        if (!scrollbarsRefreshed)
                                                RefreshScrollBars ();
+
                                        if (disp_y == Rows.Count - 1)
                                                delta_y = verticalScrollBar.Maximum - verticalScrollBar.Value;
                                        else
index db6711f614d2bdc0970e45f518ea3d501136fc1f..6b8a4b6c97009321b75bed7b25e30d8b40cdd21d 100644 (file)
@@ -1,3 +1,7 @@
+2009-03-08  Ivan N. Zlatev  <contact@i-nz.net>
+
+       * DataGridViewTest.cs: Add tests for CurrentCell.
+
 2009-03-08  Ivan N. Zlatev  <contact@i-nz.net>
 
        * DataGridViewTest.cs: Add tests for ColumnCount.
index 85806219f6c62c58f1b6590787379941a2a73c78..c7e46dd9ab8e67c1e06dc17dc1731998cb089455 100644 (file)
@@ -1715,6 +1715,55 @@ namespace MonoTests.System.Windows.Forms
                        Rectangle rowRect = dgv.GetRowDisplayRectangle (dgv.RowCount - 1, false);
                        Assert.AreEqual (true, dgv.DisplayRectangle.Contains (rowRect), "#01");
                }
+
+               [Test]
+               public void CurrentCell()
+               {
+                       DataGridView dgv = new DataGridView ();
+                       dgv.AllowUserToAddRows = false;
+
+                       Assert.IsNull (dgv.CurrentCell, "A1");
+
+                       dgv.RowCount = 10;
+                       dgv.ColumnCount = 2;
+                       Assert.AreEqual (10, dgv.RowCount, "B1");
+                       Assert.AreEqual (2, dgv.ColumnCount, "B2");
+                       Assert.IsNull (dgv.CurrentCell, "B3");
+
+                       dgv.CurrentCell = dgv[1, 9];
+                       Assert.IsNotNull (dgv.CurrentCell, "H1");
+                       Assert.AreEqual (9, dgv.CurrentCell.RowIndex, "H2");
+                       Assert.AreEqual (1, dgv.CurrentCell.ColumnIndex, "H3");
+                       
+                       dgv.CurrentCell = null;
+                       Assert.IsNull (dgv.CurrentCell, "C1");
+
+                       dgv.CurrentCell = dgv[1, 9];
+                       Assert.IsNotNull (dgv.CurrentCell, "D1");
+                       Assert.AreEqual (9, dgv.CurrentCell.RowIndex, "D2");
+                       Assert.AreEqual (1, dgv.CurrentCell.ColumnIndex, "D3");
+
+                       dgv.RowCount = 9;
+                       Assert.IsNotNull (dgv.CurrentCell, "E1");
+                       Assert.AreEqual (8, dgv.CurrentCell.RowIndex, "E2");
+                       Assert.AreEqual (1, dgv.CurrentCell.ColumnIndex, "E3");
+
+                       dgv.CurrentCell = dgv[0, 4];
+                       dgv.RowCount = 2;
+                       Assert.IsNotNull (dgv.CurrentCell, "F1");
+                       Assert.AreEqual (1, dgv.CurrentCell.RowIndex, "F2");
+                       Assert.AreEqual (0, dgv.CurrentCell.ColumnIndex, "F3");
+
+                       dgv.RowCount = 0;
+                       Assert.IsNull (dgv.CurrentCell, "G1");
+
+                       dgv.RowCount = 10;
+                       Assert.AreEqual (10, dgv.RowCount, "I1");
+                       dgv.CurrentCell = dgv[0, 4];
+                       dgv.ColumnCount = 0;
+                       Assert.AreEqual (0, dgv.RowCount, "I2");
+                       Assert.IsNull (dgv.CurrentCell, "I3");
+               }
        }
        
        [TestFixture]