From 459ffcff617dd59d6129c804af8a25636782c38f Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sat, 28 Sep 2019 23:00:33 +0200 Subject: [PATCH] Remember wxBitmapComboBox selection when recreating the control Recreate the control with the correct height when adding the first item with bitmap. --- src/msw/bmpcbox.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/msw/bmpcbox.cpp b/src/msw/bmpcbox.cpp index d2d48ab06c..1d8fc3fa7b 100644 --- a/src/msw/bmpcbox.cpp +++ b/src/msw/bmpcbox.cpp @@ -127,6 +127,7 @@ void wxBitmapComboBox::RecreateControl() // mouse-wheel behaviour. // wxString value = GetValue(); + int selection = GetSelection(); wxPoint pos = GetPosition(); wxSize size = GetSize(); size.y = GetBestSize().y; @@ -210,6 +211,8 @@ void wxBitmapComboBox::RecreateControl() // Revert the old string value if ( !HasFlag(wxCB_READONLY) ) ChangeValue(value); + else if ( selection != wxNOT_FOUND ) + SetSelection(selection); // If disabled we'll have to disable it again after re-creating if ( !IsEnabled() ) @@ -407,7 +410,7 @@ int wxBitmapComboBox::DoInsertItems(const wxArrayStringsAdapter & items, bool wxBitmapComboBox::OnAddBitmap(const wxBitmap& bitmap) { - if ( wxBitmapComboBoxBase::OnAddBitmap(bitmap) ) + if ( wxBitmapComboBoxBase::OnAddBitmap(bitmap) || !GetCount() ) { // Need to recreate control for a new measureitem call? int prevItemHeight = ::SendMessage(GetHwnd(), CB_GETITEMHEIGHT, 0, 0);