diff --git a/src/osx/cocoa/combobox.mm b/src/osx/cocoa/combobox.mm index 1666c33b83..d98f0a331e 100644 --- a/src/osx/cocoa/combobox.mm +++ b/src/osx/cocoa/combobox.mm @@ -95,9 +95,21 @@ int wxNSComboBoxControl::GetSelectedItem() const void wxNSComboBoxControl::SetSelectedItem(int item) { - wxASSERT_MSG(item >= 0 && item < [m_comboBox numberOfItems], "Inavlid item index."); SendEvents(false); - [m_comboBox selectItemAtIndex: item]; + + if ( item != wxNOT_FOUND ) + { + wxASSERT_MSG( item >= 0 && item < [m_comboBox numberOfItems], + "Inavlid item index." ); + [m_comboBox selectItemAtIndex: item]; + } + else // remove current selection (if we have any) + { + const int sel = GetSelectedItem(); + if ( sel != wxNOT_FOUND ) + [m_comboBox deselectItemAtIndex:sel]; + } + SendEvents(true); } diff --git a/src/osx/combobox_osx.cpp b/src/osx/combobox_osx.cpp index 214bdbdff4..8ab1cf9c1e 100644 --- a/src/osx/combobox_osx.cpp +++ b/src/osx/combobox_osx.cpp @@ -186,12 +186,15 @@ int wxComboBox::FindString(const wxString& s, bool bCase) const wxString wxComboBox::GetString(unsigned int n) const { + wxCHECK_MSG( n < GetCount(), wxString(), "Invalid combobox index" ); + return GetComboPeer()->GetStringAtIndex(n); } wxString wxComboBox::GetStringSelection() const { - return GetString(GetSelection()); + const int sel = GetSelection(); + return sel == wxNOT_FOUND ? wxString() : GetString(sel); } void wxComboBox::SetString(unsigned int n, const wxString& s)