diff options
author | Jim Westfall <jwestfall@surrealistic.net> | 2014-11-11 06:20:56 +0300 |
---|---|---|
committer | Jim Westfall <jwestfall@surrealistic.net> | 2014-11-11 06:20:56 +0300 |
commit | 5a5c6836967d924d1f88be6b42d0c93d504130c8 (patch) | |
tree | 1cd8047fe678b5331cc6e26c4adddcff4da8b080 /mcs/class/Managed.Windows.Forms/System.Windows.Forms | |
parent | c09cd684b45de5345e72a7f341b3de7156c89cc2 (diff) |
[MWF] DataGridView: ensure first_row_index will be valid after row removal
DataGridView keeps track of the first visible row in first_row_index.
DataGridViewRowCollection will notify DataGridView its about to delete 1 or
more rows via OnRowsPreRemovedInternal(). When this happens, we need to
ensure first_row_index will still fall within the number of rows that
will remain after the row removal.
This fixes https://bugzilla.xamarin.com/show_bug.cgi?id=24372 which I
reported.
Diffstat (limited to 'mcs/class/Managed.Windows.Forms/System.Windows.Forms')
-rw-r--r-- | mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs index 393d5cba9ae..fc213814767 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs @@ -5133,7 +5133,14 @@ namespace System.Windows.Forms { SetSelectedRowCore (rowIndex, false); } - if (Rows.Count - e.RowCount <= 0) { + int RowsLeft = Rows.Count - e.RowCount; + if (RowsLeft < 0) + RowsLeft = 0; + + if (first_row_index > RowsLeft) + first_row_index = RowsLeft; + + if (RowsLeft == 0) { MoveCurrentCell (-1, -1, true, false, false, true); hover_cell = null; } else if (Columns.Count == 0) { @@ -5141,8 +5148,8 @@ namespace System.Windows.Forms { hover_cell = null; } else if (currentCell != null && currentCell.RowIndex == e.RowIndex) { int nextRowIndex = e.RowIndex; - if (nextRowIndex >= Rows.Count - e.RowCount) - nextRowIndex = Rows.Count - 1 - e.RowCount; + if (nextRowIndex >= RowsLeft) + nextRowIndex = RowsLeft - 1; MoveCurrentCell (currentCell != null ? currentCell.ColumnIndex : 0, nextRowIndex, true, false, false, true); if (hover_cell != null && hover_cell.RowIndex >= e.RowIndex) |