DeleteProperty on wxPropertyGrid (RIGHT CLICKED EVT) problem

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
greg
Earned some good credits
Earned some good credits
Posts: 111
Joined: Fri Sep 12, 2008 7:17 am

DeleteProperty on wxPropertyGrid (RIGHT CLICKED EVT) problem

Post 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?
Regards
Greg
jfouche
Super wx Problem Solver
Super wx Problem Solver
Posts: 442
Joined: Tue May 06, 2008 4:52 pm
Location: France

Post 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.
Jérémie
Post Reply