Get id of a changed combobox 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
torsten
In need of some credit
In need of some credit
Posts: 1
Joined: Wed May 07, 2008 12:39 pm

Get id of a changed combobox

Post by torsten »

Hello,

I'm writing a programm with an unknown number of comboboxes which are defined in a xrc file. To get the value of the comboboxes I wanted to use just one event function for all comboboxes. But to get the value I need the id of the changed combobox. How do I get this id?

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

Post by Jorg »

That is a tough one. What you want is an XRC generated ID te be identified by you without knowing what ID belongs to what XRCCTRL string?

I don't think you can do that easily.. The XRC string is not stored in the control. What you can do is create a custom XRC handler, and handle the comboboxes yourself. When for example you have to instantiate an XRC control with a certain name (convention) you can store the generated ID together with the string or pointer that identifies it in a hash map. Then upon an event, look at what ID belongs to what control.

Handling all comboboxes with one event is easy, simply specify -1 as ID and all events of that type will be sent to that one handler ..

http://docs.wxwidgets.org/trunk/classwx ... ndler.html
http://wiki.wxwidgets.org/XRC

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Re: Get id of a changed combobox

Post by benedicte »

torsten wrote:Hello,

I'm writing a programm with an unknown number of comboboxes which are defined in a xrc file. To get the value of the comboboxes I wanted to use just one event function for all comboboxes. But to get the value I need the id of the changed combobox. How do I get this id?

Thanks
Use the following:

Code: Select all


BEGIN_EVENT_TABLE(MyClass, BaseClass)
..
EVT_COMBOBOX (wxID_ANY, MyClass::MyHandler)
..
END_EVENT_TABLE()

void MyClass::MyHandler (wxCommandEvent &event)
{
   int combo_id = event.GetId();
   //...
}
Post Reply