dynamic submenu id?

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
curtisnewton
In need of some credit
In need of some credit
Posts: 8
Joined: Thu Aug 28, 2014 12:24 pm

dynamic submenu id?

Post by curtisnewton »

hello

I create a menu with many submenus (with the same ID) in a for loop (menu is created dyamicaly)
but in the event, how do I differentiate them as the event occur?
I tried GetString() but it returns an empty string
GetInt() returns always 1

thanks
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: dynamic submenu id?

Post by doublemax »

You shouldn't use the same id for multiple menu items. Use wxID_ANY, this should assign a new id internally. Then in the event handler you can get the current menu item using event.GetId() and wxMenuBar::FindItem().
Use the source, Luke!
curtisnewton
In need of some credit
In need of some credit
Posts: 8
Joined: Thu Aug 28, 2014 12:24 pm

Re: dynamic submenu id?

Post by curtisnewton »

doublemax wrote:You shouldn't use the same id for multiple menu items. Use wxID_ANY, this should assign a new id internally. Then in the event handler you can get the current menu item using event.GetId() and wxMenuBar::FindItem().
ok thx

but using wxID_ANY then how do I know witch ID is assigned to witch menu ?
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: dynamic submenu id?

Post by doublemax »

With the methods i mentioned above you can access the menu item which gives you the text of the menu. If that's not enough, the best solution depends on your actual task, what kind of information you need to transport to the event handler.

The most generic way would be to derive your own class from wxMenuItem and use wxMenu::Append( wxMenuItem *menuItem) to add it to the menu. That way you can transport any information you like inside the menu item.
Use the source, Luke!
Post Reply