Events and wxTreeCtrl

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
romeo9423
Experienced Solver
Experienced Solver
Posts: 72
Joined: Mon Nov 08, 2004 3:36 pm

Events and wxTreeCtrl

Post by romeo9423 » Tue Dec 20, 2005 7:03 pm

Hi,

I have a class deriving from wxTreeCtrl like this :



class PrjTree : public wxTreeCtrl
{
...
};

and I would like to handle context menu. So I tried this in implementation file

BEGIN_EVENT_TABLE(PrjTree, wxTreeCtrl)
EVT_TREE_ITEM_RIGHT_CLICK(idPrjTree, PrjTree::OnItemRClick)
EVT_MENU(idAddCardCmd, PrjTree::OnAddCardCmd)
END_EVENT_TABLE()


Problem is about EVT_MENU because I get this error :

invalid static_cast error from type void (PrjTree::*) (wxTreeEvent&) to type void (wxEventHandler::*) (wxCommandEvent&)


Does it mean that actually I need to declare a class deriving from wxEventHandler and including a wxTreeCtrl ?

I am a bit lost ...

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Tue Dec 20, 2005 7:25 pm

Simply handle the right mouse click on the control (or right mouse select) and use wxPopupMenu for your menu. The EVT_MENU is only meant for wxMenu and wxMenuItem classes.

With regards,
- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

Cursor
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Aug 29, 2004 3:09 pm
Location: Grenoble, France
Contact:

Post by Cursor » Tue Dec 20, 2005 7:48 pm

Simply use the appropriate wxEvent derivate class.
The wxMenu event fires a wxCommandEvent and you intercept a wxTreeEvent.

Replace :
void PrjTree::OnAddCardCmd(wxTreeEvent& event)
by :
void PrjTree::OnAddCardCmd(wxCommandEvent& event)
What is little and green, witch go up and down ??
Yoda playing with the force.

Post Reply