]> git.saurik.com Git - wxWidgets.git/commitdiff
don't lose the contents of the combobox if it was set to a value not in a list and...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 9 Feb 2008 15:22:15 +0000 (15:22 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 9 Feb 2008 15:22:15 +0000 (15:22 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51616 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/choice.h
src/msw/choice.cpp

index 402948e08af5e24c0602f27fc16c45cd1caf3778..8be304b782060387bca8e7fa72447f132e036293 100644 (file)
@@ -66,6 +66,8 @@ public:
                 const wxValidator& validator = wxDefaultValidator,
                 const wxString& name = wxChoiceNameStr);
 
+    virtual void SetLabel(const wxString& label);
+
     virtual unsigned int GetCount() const;
     virtual int GetSelection() const;
     virtual int GetCurrentSelection() const;
index 9eec9c2332422433a5166bbbd315c221a5af77cb..7b73e6f6f1d0106c0ce347d08d08db42fcba6c0e 100644 (file)
@@ -158,6 +158,21 @@ bool wxChoice::CreateAndInit(wxWindow *parent,
     return true;
 }
 
+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::Create(wxWindow *parent,
                       wxWindowID id,
                       const wxPoint& pos,