diff --git a/include/wx/gtk/combobox.h b/include/wx/gtk/combobox.h index 02ae7e481a..e31a347c8e 100644 --- a/include/wx/gtk/combobox.h +++ b/include/wx/gtk/combobox.h @@ -88,6 +88,9 @@ public: { return wxItemContainer::GetStringSelection(); } + + virtual void SetString(unsigned int n, const wxString& string); + virtual void Popup(); virtual void Dismiss(); diff --git a/interface/wx/combobox.h b/interface/wx/combobox.h index f692cc578b..8a78e9c4c8 100644 --- a/interface/wx/combobox.h +++ b/interface/wx/combobox.h @@ -314,7 +314,15 @@ public: virtual int FindString(const wxString& s, bool bCase = false) const; virtual wxString GetString(unsigned int n) const; virtual wxString GetStringSelection() const; - virtual void SetString(unsigned int n, const wxString& s); + + /** + Changes the text of the specified combobox item. + + Notice that if the item is the currently selected one, i.e. if its text + is displayed in the text part of the combobox, then the text is also + replaced with the new @a text. + */ + virtual void SetString(unsigned int n, const wxString& text); virtual unsigned int GetCount() const; }; diff --git a/src/gtk/combobox.cpp b/src/gtk/combobox.cpp index 045c6166ba..445a6cddb1 100644 --- a/src/gtk/combobox.cpp +++ b/src/gtk/combobox.cpp @@ -282,6 +282,19 @@ void wxComboBox::SetValue(const wxString& value) wxTextEntry::SetValue(value); } +void wxComboBox::SetString(unsigned int n, const wxString& text) +{ + wxChoice::SetString(n, text); + + if ( static_cast(n) == GetSelection() ) + { + // We also need to update the currently shown text, for consistency + // with wxMSW and also because it makes sense as leaving the old string + // in the text but not in the list would be confusing to the user. + SetValue(text); + } +} + // ---------------------------------------------------------------------------- // standard event handling // ----------------------------------------------------------------------------