wxComboBox not triggering events

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
Tyler
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 246
Joined: Fri Sep 03, 2004 12:37 am
Contact:

wxComboBox not triggering events

Post by Tyler » Thu Dec 30, 2004 8:48 pm

I have a wxComboBox with one option in it. If I select the only option in my combo box, the function I've instantiated for my EVT_COMBOBOX macro gets called. Subsequent selections of the only option in the combo box, however, do not trigger a call to my function for this event.

What I assume is that the wxComboBox is only throwing out wxEVT_COMMAND_COMBOBOX_SELECTED events if a new value is selected in the combo box. Am I wrong or is this how the combo box really functions? The documentation for this event macro reads:

Code: Select all

EVT_COMBOBOX(id, func) 	Process a wxEVT_COMMAND_COMBOBOX_SELECTED event, when an item on the list is selected.
This doesn't say "when a different item is selected", so I assume that I must be doing something wrong.

Does anyone know how I can send a wxEVT_COMMAND_COMBOBOX_SELECTED when I select the same item on the combo box again and again?

Thanks for your help.

-Tyler

Tyler
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 246
Joined: Fri Sep 03, 2004 12:37 am
Contact:

Post by Tyler » Thu Dec 30, 2004 11:12 pm

It appears that this is the native functioning for the wxComboBox. I experimented with the wxWindows sample "widgets" and observed the same behavior there.

For anyone else who has this problem, I resolved the issue by switching to a wxChoice class instead of wxComboBox. This throws an EVT_CHOICE no matter which option I select, which is very useful.

Frank
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Jan 01, 2005 6:19 pm

Post by Frank » Sat Jan 01, 2005 6:37 pm

I have a similar Problem.

In my case, my Combobox has several items, but I'm using it as a history-box. The last item the user selected will be copied to the top of the list. I use this code:

Code: Select all

int idx = m_cbPackages->FindString(m_lastPackage.c_str());
if (idx != wxNOT_FOUND) m_cbPackages->Delete(idx);
idx = m_cbPackages->Insert(m_lastPackage.c_str(), 0);
m_cbPackages->Select(idx);
m_cbPackages is my combobox, m_lastPackage is a std::string wich contains the last selection the user did (this can be from the combobox or from a filedialog).

When I select an item, that was previosly at the position of the former old item (that is now on top of the list), the combobox will not call my Event.

This problem occours in 2.5.3 only. In 2.5.2 it works. I think this is some kind of optimization implemented in 2.5.3 to fire the event only if a new item is selected.

I would try wxChoice, as Tyler suggests. But as far as I understand the wxChoice has a different apearance on Non-Windows Plattforms.

Any hints how to workaround this problem?

Tyler
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 246
Joined: Fri Sep 03, 2004 12:37 am
Contact:

Post by Tyler » Tue Jan 04, 2005 11:16 am

Hey Frank,

That is the deeper problem I was referring to as well. It's almost as if, the last mouse selected text gets saved in memory, and any call to SetValue, SetStringSelection, Insert, etc does not alter this data in memory, such that the only way it can be changed is through another mouse click. Whereby this has the end effect of not sending the events appropriately. I suppose they didn't bother to put this optimization into wxChoice (thank goodness).

You mentioned that wxChoice appears different on non-Windows platforms. I was not aware of that. Do you have any screenshots that show this? (installing wx on my linux box would be a bit much just to see).

Perhaps I will post this thread to the wxWidgets bugs/feature request forum. Only problem is, if it's true that as you mentioned this was changed between 2.5.2 and 2.5.3, I could see it getting changed indiscriminately in the future as well. Just a thought.

Thanks

-Tyler

Frank
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Jan 01, 2005 6:19 pm

Post by Frank » Tue Jan 04, 2005 3:53 pm

Hi Tyler,

On the wxChoice-Look. I'm not sure. I think I read that somewhere, but I never tried or saw it on Linux. I could be confusing it with FOX-Toolkit, maybee I should try it someday...

On our Problem: I took a look in the wx sources. I checked out the CVS-Version. The change was incorporated in version 1.87 of combobox.cpp. From the comments it seems to be a workaround to another problem that leads to double-firing the event.

Another thing I noticed in the code is probably the workaround I looked for. The function

void wxComboBox::SetValue(const wxString& value)

is reseting the value for the old selection (called m_selectionOld). I will test it this afternoon, it seems all I have to do is call SetValue() to set the remembered last selection to the correct value. In your case, with only one item... Dunno...

-Frank

Sickboy
Experienced Solver
Experienced Solver
Posts: 91
Joined: Wed Mar 16, 2005 10:30 pm
Location: Germany

Post by Sickboy » Thu Mar 31, 2005 12:45 pm

Setting back m_selectionOld to -1 after every seleection in a derived wxCombobox works.

Has anyone take a look at 2.5.4 if it has been fixed ?

Post Reply