diff options
author | Miguel de Icaza <miguel@gnome.org> | 2014-11-26 21:02:16 +0300 |
---|---|---|
committer | Miguel de Icaza <miguel@gnome.org> | 2014-11-26 21:02:16 +0300 |
commit | 4e9a0636c24e5f7114b98c558398412c73af766f (patch) | |
tree | 4f53b0f8bac058ce7111cc1965d30134a4b38290 /mcs/class/Managed.Windows.Forms/System.Windows.Forms | |
parent | 668fdf5e8af827701e5da2f30b3c5c37e021f805 (diff) | |
parent | 24742dc038d520294578cf29a756b943ade221b9 (diff) |
Merge pull request #1398 from jwestfall69/dgv-first_row_index
[MWF] DataGridView: ensure first_row_index will be valid after row removal
Diffstat (limited to 'mcs/class/Managed.Windows.Forms/System.Windows.Forms')
-rw-r--r-- | mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs | 16 |
1 files changed, 13 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..3ce4ab7b574 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,17 @@ 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 - 1) + first_row_index = RowsLeft - 1; + + if (first_row_index < 0) + first_row_index = 0; + + if (RowsLeft == 0) { MoveCurrentCell (-1, -1, true, false, false, true); hover_cell = null; } else if (Columns.Count == 0) { @@ -5141,8 +5151,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) |