How to show a menu on a wxTreeCtrl item right click?? Topic is solved

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
vdumont
I live to help wx-kind
I live to help wx-kind
Posts: 155
Joined: Wed Mar 29, 2006 7:13 pm
Location: QC,Canada

How to show a menu on a wxTreeCtrl item right click??

Post by vdumont »

Hi, I'd like to show a menu when the user right-click on a wxTreeCtrl item. Thank you for any help.
Vexator
I live to help wx-kind
I live to help wx-kind
Posts: 187
Joined: Sun Jan 30, 2005 2:50 pm
Location: Heidelberg, Germany

Post by Vexator »

Windows 7 Pro
Visual Studio 2010
wxWidgets 2.9.3
phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Post by phlox81 »

You should subclass the wxTreeCtrl and Implement a MouseEvent.
http://forums.wxwidgets.org/viewtopic.p ... rl+hittest

I mostly derive from wxTreeItemData a DataBase Class for my Tree,
and also give this class a virtual Method called makeMenu(wxMenu& menu).
So that I can define in every Nodeclass my own Menu.
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

There are 2 events you can handle:
EVT_TREE_ITEM_RIGHT_CLICK and EVT_TREE_ITEM_MENU.
vdumont
I live to help wx-kind
I live to help wx-kind
Posts: 155
Joined: Wed Mar 29, 2006 7:13 pm
Location: QC,Canada

Post by vdumont »

Hi thanks for your help.


The problem I have now is that I'd like to know which item I right clicked so when I press example "ACTIVATE" in the menu that pops up, the action is taken for the item that was right clicked.


event.GetItem() returns a wxTreeItemData item right? How can I convert this item into a MyTreeItemData class object? :cry:
phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Post by phlox81 »

MyTreeItemData* pitemdata = (MyTreeItemData*)this->GetItemData(event.GetItem());
vdumont
I live to help wx-kind
I live to help wx-kind
Posts: 155
Joined: Wed Mar 29, 2006 7:13 pm
Location: QC,Canada

Post by vdumont »

Sounds good I'll try this out ;) thanks!
Post Reply