From 96ef6ea2939832fece9720b5bee11a6ba58b3cea Mon Sep 17 00:00:00 2001 From: jonkraber Date: Sat, 18 Jun 2016 18:12:52 +0200 Subject: [PATCH] Fix preserving selection when changing selection mode in wxGrid The loop over the existing selection was buggy and took into account only one corner of the block instead of the entire block and also skipped some blocks entirely. Closes #17572. --- docs/changes.txt | 1 + src/generic/gridsel.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 290420065b..88a119573b 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -90,6 +90,7 @@ All (GUI): - Add wxListCtrl::SetHeaderAttr(). - Add support for using markup in wxDataViewCtrl text items. - Implement auto complete in generic wxSearchCtrl (Eric Jensen). +- Fix preserving selection when changing selection mode in wxGrid (jonkraber). wxGTK: diff --git a/src/generic/gridsel.cpp b/src/generic/gridsel.cpp index c6cf59f389..3f0f3f596b 100644 --- a/src/generic/gridsel.cpp +++ b/src/generic/gridsel.cpp @@ -144,14 +144,15 @@ void wxGridSelection::SetSelectionMode( wxGrid::wxGridSelectionModes selmode ) } // Note that m_blockSelectionTopLeft's size may be changing! - for (n = 0; n < m_blockSelectionTopLeft.GetCount(); n++) + for ( n = m_blockSelectionTopLeft.GetCount(); n > 0; ) { + n--; wxGridCellCoords& coords = m_blockSelectionTopLeft[n]; int topRow = coords.GetRow(); int leftCol = coords.GetCol(); - coords = m_blockSelectionBottomRight[n]; - int bottomRow = coords.GetRow(); - int rightCol = coords.GetCol(); + wxGridCellCoords& coords2 = m_blockSelectionBottomRight[n]; + int bottomRow = coords2.GetRow(); + int rightCol = coords2.GetCol(); if (selmode == wxGrid::wxGridSelectRows) {