From 0b0437af20b06526474f77aea1fcff066062847f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 17 Oct 2023 02:05:12 +0200 Subject: [PATCH] Fix refreshing wxGenericListCtrl with multiple selection Changing the selection could behave wrongly and result in an assert failure as the selection anchor could have become invalid, due to the change of the number of items in the control. Fix this by invalidating it when this happens. (cherry picked from commit 5885eea5ea72434311f2c706f57cff92a09ade91) --- docs/changes.txt | 4 ++++ src/generic/listctrl.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index 6eae8eaf00..05ea6bfa61 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -235,6 +235,10 @@ Changes in behaviour which may result in build errors 3.2.4: (released 2024-??-??) ---------------------------- +All (GUI): + +- Fix refreshing multiple selection items in generic wxListCtrl. + wxMSW: - Fix MSVS warning about redundant "const" in wx/itemid.h (#23590). diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 3c955aeb1e..943ffdd2c3 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -3782,6 +3782,10 @@ void wxListMainWindow::SetItemCount(long count) if ( HasCurrent() && m_current >= (size_t)count ) ChangeCurrent(count - 1); + // And do the same thing for the multiple selection anchor. + if ( m_anchor != (size_t)-1 && m_anchor >= (size_t)count ) + m_anchor = count - 1; + m_selStore.SetItemCount(count); m_countVirt = count;