From 61989086f2c26549f56db4e817da6ec35c14cbde Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Mon, 20 Sep 2021 22:07:37 +0200 Subject: [PATCH] Retain selection of wxComboBox item whose text has been changed In wxComboBox::SetString() implementation for wxMac the item is first removed from the list so its selection is invalidated. We have to retain it so we need to re-select just inserted item. --- src/osx/combobox_osx.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/osx/combobox_osx.cpp b/src/osx/combobox_osx.cpp index aa377cd9a5..708762397d 100644 --- a/src/osx/combobox_osx.cpp +++ b/src/osx/combobox_osx.cpp @@ -207,8 +207,15 @@ void wxComboBox::SetString(unsigned int n, const wxString& s) // Notice that we shouldn't delete and insert the item in this control // itself as this would also affect the client data which we need to // preserve here. + const int sel = GetSelection(); GetComboPeer()->RemoveItem(n); GetComboPeer()->InsertItem(n, s); + // When selected item is removed its selection is invalidated + // so we need to re-select it manually. + if ( sel == n ) + { + SetSelection(n); + } SetValue(s); // changing the item in the list won't update the display item }