X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/275c64304eadef874676ab4aa3663a0f8feefd5d..51ec29ea5d1d1093bafbae27a8483211a90d9659:/src/msw/choice.cpp diff --git a/src/msw/choice.cpp b/src/msw/choice.cpp index 3fd0fefc5a..34dd9b817d 100644 --- a/src/msw/choice.cpp +++ b/src/msw/choice.cpp @@ -358,6 +358,10 @@ void wxChoice::SetString(unsigned int n, const wxString& s) else if ( HasClientObjectData() ) oldObjData = GetClientObject(n); + // and also the selection if we're going to delete the item that was + // selected + const bool wasSelected = static_cast(n) == GetSelection(); + ::SendMessage(GetHwnd(), CB_DELETESTRING, n, 0); ::SendMessage(GetHwnd(), CB_INSERTSTRING, n, (LPARAM)s.wx_str() ); @@ -367,6 +371,11 @@ void wxChoice::SetString(unsigned int n, const wxString& s) else if ( oldObjData ) SetClientObject(n, oldObjData); + // and the selection + if ( wasSelected ) + SetSelection(n); + + // the width could have changed so the best size needs to be recomputed InvalidateBestSize(); }