Page 1 of 1

DeleteProperty on wxPropertyGrid (RIGHT CLICKED EVT) problem

Posted: Sat Jan 22, 2011 4:38 pm
by greg
I have a problem while deleting property from wxPropertyGrid widget when property is selected and right clicked.
Here is my snippet:

Code: Select all

class MyFrame : public wxFrame
{
private:
    wxPropertyGrid* pg;

    void OnPropertyGridItemRightClick( wxPropertyGridEvent& event );
    DECLARE_EVENT_TABLE()
};

BEGIN_EVENT_TABLE(MyFrame, wxFrame)  EVT_PG_RIGHT_CLICK(wxID_ANY,MyFrame::OnPropertyGridItemRightClick )
END_EVENT_TABLE()


void MyFrame::OnPropertyGridItemRightClick( wxPropertyGridEvent& event )
{
	wxPGProperty* p = event.GetProperty();

	if ( p )
	{
	if (p->IsCategory())
		{
		pg->DeleteProperty ( p ); //here is a problem and property can not be deleted
		}
	}
}
Can anybody help me?

Posted: Mon Jan 24, 2011 9:28 am
by jfouche
Hi

It looks like this bug. May be you're using an old version of wxPropGrid, or the bug is not fully fixed for right_click event.

Try to post a custom event to remove the property out of the right click handler (I think the pb comes from the fact the property is used after OnPropertyGridItemRightClick is called in wxPropertyGrid library) :

Code: Select all

void MyFrame::OnPropertyGridItemRightClick( wxPropertyGridEvent& event )
{
  wxPGProperty* p = event.GetProperty();
  if ( p )
  {
    if (p->IsCategory())
    {
      wxPropertyGridEvent delEvent(MY_PG_DELETE_PROPERTY, ...);
      delEvent.SetProperty( p );
      AddPendingEvent(delEvent);
    }
  }
}

void MyFrame::OnPropertyGridDeleteProperty( wxPropertyGridEvent& event )
{
  pg->DeleteProperty ( event.GetProperty() ); 
}
Check also wxPropertyGrid trunk, to see if you also encounter the problem, and fill a bug.