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.
This commit is contained in:
Artur Wieczorek
2021-09-20 22:07:37 +02:00
committed by AW
parent 2f3fc152bf
commit 61989086f2

View File

@@ -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
}