Fix crash in propgrid sample, see #18537

This commit is contained in:
Paul Cornett 2019-10-22 19:51:50 -07:00
parent ab33227578
commit ffac936882

View File

@ -2985,21 +2985,23 @@ void FormMain::OnSetPropertyValue( wxCommandEvent& WXUNUSED(event) )
void FormMain::OnInsertChoice( wxCommandEvent& WXUNUSED(event) ) void FormMain::OnInsertChoice( wxCommandEvent& WXUNUSED(event) )
{ {
wxPropertyGrid* pg = m_pPropGridManager->GetGrid(); wxPropertyGrid* pg = m_pPropGridManager->GetGrid();
wxPGProperty* selected = pg->GetSelection(); 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() ) if ( choices.IsOk() )
{ {
// Insert new choice to the center of list
int pos = choices.GetCount() / 2; int pos = choices.GetCount() / 2;
selected->InsertChoice("New Choice", pos); selected->InsertChoice("New Choice", pos);
return;
} }
else
{
::wxMessageBox("First select a property with some choices.");
} }
wxMessageBox("First select a property with some choices.");
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@ -3007,21 +3009,23 @@ void FormMain::OnInsertChoice( wxCommandEvent& WXUNUSED(event) )
void FormMain::OnDeleteChoice( wxCommandEvent& WXUNUSED(event) ) void FormMain::OnDeleteChoice( wxCommandEvent& WXUNUSED(event) )
{ {
wxPropertyGrid* pg = m_pPropGridManager->GetGrid(); wxPropertyGrid* pg = m_pPropGridManager->GetGrid();
wxPGProperty* selected = pg->GetSelection(); 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() ) if ( choices.IsOk() )
{ {
// Deletes choice from the center of list
int pos = choices.GetCount() / 2; int pos = choices.GetCount() / 2;
selected->DeleteChoice(pos); selected->DeleteChoice(pos);
return;
} }
else
{
::wxMessageBox("First select a property with some choices.");
} }
wxMessageBox("First select a property with some choices.");
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------