From a6cc89777b63f97ba6dfa84c667ceb3f7876ff2d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 4 Feb 2024 02:20:19 +0100 Subject: [PATCH] Allow passing -1 to wxPGProperty::SetChoiceSelection() again This used to be possible in 3.0 but was disallowed back in 29bf859fae (Check if new index is in range before selecting new value in wxPGProperty::SetChoiceSelection., 2014-11-29). However there doesn't seem to be any real harm in still allowing to do this, so handle -1 as a special case here. Closes #24279. Closes #24281. --- interface/wx/propgrid/property.h | 3 +++ src/propgrid/property.cpp | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/interface/wx/propgrid/property.h b/interface/wx/propgrid/property.h index e86656fd88..5e975b6c16 100644 --- a/interface/wx/propgrid/property.h +++ b/interface/wx/propgrid/property.h @@ -1885,6 +1885,9 @@ public: Tries to retain value type, although currently if it is not string, then it is forced to integer. + + If @a newValue is wxNOT_FOUND (`-1`), then the property's value is + reset to unspecified, as if SetValueToUnspecified() was called. */ void SetChoiceSelection( int newValue ); diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index d955683d8f..41b45f8f4d 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -2217,6 +2217,15 @@ int wxPGProperty::GetChoiceSelection() const void wxPGProperty::SetChoiceSelection( int newValue ) { wxCHECK_RET( m_choices.IsOk(), wxS("invalid choiceinfo") ); + + // Allow setting the value of -1 to reset the selection, for consistency + // with wxChoice::SetSelection(). + if ( newValue == wxNOT_FOUND ) + { + SetValueToUnspecified(); + return; + } + wxCHECK_RET( newValue >= 0 && newValue < (int)m_choices.GetCount(), wxS("New index is out of range") );