diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index fc1a0057fd..2f5228fbb3 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -1898,20 +1898,19 @@ int wxPGProperty::InsertChoice( const wxString& label, int index, int value ) wxPropertyGrid* pg = GetGrid(); const int sel = GetChoiceSelection(); - if ( index == wxNOT_FOUND ) - index = m_choices.GetCount(); + int newSel = sel; - int newSel; - if ( sel == wxNOT_FOUND ) - newSel = 0; - else if ( index <= sel ) - newSel = sel + 1; - else - newSel = sel; + const int numChoices = m_choices.GetCount(); + if ( index == wxNOT_FOUND ) + index = numChoices; + + if ( numChoices > 0 && index <= sel ) + newSel++; m_choices.Insert(label, index, value); - - if ( sel != newSel ) + // Set new selection if it was modified + // or if the first element was added. + if ( sel != newSel || numChoices == 0 ) SetChoiceSelection(newSel); if ( pg && this == pg->GetSelection() ) diff --git a/src/propgrid/props.cpp b/src/propgrid/props.cpp index 5697727281..422e1f84ca 100644 --- a/src/propgrid/props.cpp +++ b/src/propgrid/props.cpp @@ -1102,7 +1102,7 @@ WX_PG_IMPLEMENT_PROPERTY_CLASS(wxEnumProperty, wxPGProperty, wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, const wxChar* const* labels, const long* values, int value ) : wxPGProperty(label,name) { - SetIndex(wxNOT_FOUND); + SetIndex(0); if ( labels ) { @@ -1144,7 +1144,7 @@ wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, const wxArrayString& labels, const wxArrayInt& values, int value ) : wxPGProperty(label,name) { - SetIndex(wxNOT_FOUND); + SetIndex(0); if ( &labels && labels.size() ) {