From 6fb64da9226832101eed8f4ec4fce5c5d81252b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C4=83t=C4=83lin=20R=C4=83ceanu?= Date: Wed, 13 Oct 2021 03:58:39 +0300 Subject: [PATCH] Fix selection when wxOwnerDrawnComboBox contains identical items Ensure that the drop-down selection is correct even if there are multiple items with the same label in wxOwnerDrawnComboBox. See https://github.com/wxWidgets/wxWidgets/pull/2544 Closes #19289. --- src/generic/odcombo.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/generic/odcombo.cpp b/src/generic/odcombo.cpp index 22b4eefeda..c93272a11d 100644 --- a/src/generic/odcombo.cpp +++ b/src/generic/odcombo.cpp @@ -704,10 +704,20 @@ int wxVListBoxComboPopup::GetSelection() const void wxVListBoxComboPopup::SetStringValue( const wxString& value ) { - int index = m_strings.Index(value); - m_stringValue = value; + // Keep previous selection if it already corresponds to the given value + // (this is useful if there are multiple identical items in the combobox, + // we don't want to select the first one of them if another one had been + // previously selected). + if ( m_value >= 0 && m_value < (int)m_strings.size() && + value == m_strings[m_value] ) + { + return; + } + + int index = m_strings.Index(value); + if ( index >= 0 && index < (int)wxVListBox::GetItemCount() ) { wxVListBox::SetSelection(index);