diff --git a/samples/propgrid/propgrid.cpp b/samples/propgrid/propgrid.cpp index d1382516aa..4cce1563e2 100644 --- a/samples/propgrid/propgrid.cpp +++ b/samples/propgrid/propgrid.cpp @@ -2985,21 +2985,23 @@ void FormMain::OnSetPropertyValue( wxCommandEvent& WXUNUSED(event) ) void FormMain::OnInsertChoice( wxCommandEvent& WXUNUSED(event) ) { wxPropertyGrid* pg = m_pPropGridManager->GetGrid(); - wxPGProperty* selected = pg->GetSelection(); - const wxPGChoices& choices = selected->GetChoices(); - // Insert new choice to the center of list + if (selected) + { + const wxPGChoices& choices = selected->GetChoices(); - if ( choices.IsOk() ) - { - int pos = choices.GetCount() / 2; - selected->InsertChoice("New Choice", pos); - } - else - { - ::wxMessageBox("First select a property with some choices."); + if ( choices.IsOk() ) + { + // Insert new choice to the center of list + + int pos = choices.GetCount() / 2; + selected->InsertChoice("New Choice", pos); + return; + } } + + wxMessageBox("First select a property with some choices."); } // ----------------------------------------------------------------------- @@ -3007,21 +3009,23 @@ void FormMain::OnInsertChoice( wxCommandEvent& WXUNUSED(event) ) void FormMain::OnDeleteChoice( wxCommandEvent& WXUNUSED(event) ) { wxPropertyGrid* pg = m_pPropGridManager->GetGrid(); - wxPGProperty* selected = pg->GetSelection(); - const wxPGChoices& choices = selected->GetChoices(); - // Deletes choice from the center of list + if (selected) + { + const wxPGChoices& choices = selected->GetChoices(); - if ( choices.IsOk() ) - { - int pos = choices.GetCount() / 2; - selected->DeleteChoice(pos); - } - else - { - ::wxMessageBox("First select a property with some choices."); + if ( choices.IsOk() ) + { + // Deletes choice from the center of list + + int pos = choices.GetCount() / 2; + selected->DeleteChoice(pos); + return; + } } + + wxMessageBox("First select a property with some choices."); } // -----------------------------------------------------------------------