From d05d5c1687b1abcdf90e85996ee8575aaf2e4d1a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 9 Feb 2008 15:22:15 +0000 Subject: [PATCH] don't lose the contents of the combobox if it was set to a value not in a list and a popup has been opened and closed (patch 1883474) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@51616 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 2 ++ include/wx/msw/choice.h | 2 ++ src/msw/choice.cpp | 15 +++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index 118142fb99..442fdde907 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -130,6 +130,8 @@ wxMSW: - Fix assert when using owner-drawn menu items with the newest (Vista) SDK. - Fixed wxTextCtrl to not process clipboard events twice if there's a custom wxEVT_COMMAND_TEXT_* event handler. +- Fix wxComboBox to not lose the current value if it was programmatically set + to a value not in a list of choices on popup close (Kolya Kosenko) wxGTK: diff --git a/include/wx/msw/choice.h b/include/wx/msw/choice.h index a2ca016367..89014f8627 100644 --- a/include/wx/msw/choice.h +++ b/include/wx/msw/choice.h @@ -66,6 +66,8 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxChoiceNameStr); + virtual void SetLabel(const wxString& label); + virtual void Delete(unsigned int n); virtual void Clear(); diff --git a/src/msw/choice.cpp b/src/msw/choice.cpp index 63c8c66967..ef2d74dbbf 100644 --- a/src/msw/choice.cpp +++ b/src/msw/choice.cpp @@ -172,6 +172,21 @@ bool wxChoice::Create(wxWindow *parent, style, validator, name); } +void wxChoice::SetLabel(const wxString& label) +{ + if ( FindString(label) == wxNOT_FOUND ) + { + // unless we explicitly do this here, CB_GETCURSEL will continue to + // return the index of the previously selected item which will result + // in wrongly replacing the value being set now with the previously + // value if the user simply opens and closes (without selecting + // anything) the combobox popup + SetSelection(-1); + } + + wxChoiceBase::SetLabel(label); +} + bool wxChoice::MSWShouldPreProcessMessage(WXMSG *pMsg) { MSG *msg = (MSG *) pMsg;