pass treectrl item id to menu OnTreeCtrlItemMenu
Posted: Mon Nov 18, 2019 11:08 am
Hi,
I am building a treectrl which display some items. When right click on an item I want a menu to show up with some options 'delete item' 'edit item' ...
In the treectrl sample (folder wxWidgets-3.1.2\samples\treectrl) it creates the menu, but the menu items are not linked to any functions.
My issue is that I don't know how to get the treectrl item id from the called function.
First in the OnTreeCtrl2ItemMenu we can get the item id with event.GetItem() (from sample).
But then in the MemBFrame::OnDeleteNode how to get the item id? Can I just use event.GetItem()? I think maybe it's not the same event declared in the new function scope?
Thanks
I am building a treectrl which display some items. When right click on an item I want a menu to show up with some options 'delete item' 'edit item' ...
In the treectrl sample (folder wxWidgets-3.1.2\samples\treectrl) it creates the menu, but the menu items are not linked to any functions.
My issue is that I don't know how to get the treectrl item id from the called function.
First in the OnTreeCtrl2ItemMenu we can get the item id with event.GetItem() (from sample).
Code: Select all
void MemBFrame::OnTreeCtrl2ItemMenu(wxTreeEvent& event)
{
wxTreeItemId itemId = event.GetItem();
static const long idMenuDeleteNode = wxNewId();
wxMenuItem* MenuItemDeleteNode = new wxMenuItem(Menu, idMenuDeleteNode, _("Delete Node"), _("Delete all memories of this Node"), wxITEM_NORMAL);
menu.Append(MenuItemDeleteNode);
Connect(idMenuDeleteNode,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&MemBFrame::OnDeleteNode);
PopupMenu(&menu, pt);
event.Skip();
}
Thanks