wxComboBox::Clear() preventing selection from sticking?

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
buttonsrtoys
Experienced Solver
Experienced Solver
Posts: 58
Joined: Mon Jul 03, 2017 12:03 am

wxComboBox::Clear() preventing selection from sticking?

Post by buttonsrtoys »

Wx 3.1.1, Windows 10, I have a wxComboBox that I instantiate with

m_comboBoxFilename = new wxComboBox(this, wxID_ANY, wxT("Settings"), wxDefaultPosition, wxDefaultSize, 0, NULL, 0);

It works fine and I can populate the list with wxComboBox::Append(..) and set the displayed value with wxComboBox::SetValue(..). I need to occasionally clear the list and append new list values, which is where I run into trouble. When I clear the list with wxComboBox::Clear(..), ::SetValue(..) no longer sticks. It displays when I step thru the code setting its value:
combo_box_1.JPG
combo_box_1.JPG (13.78 KiB) Viewed 722 times
but when return control to Wx, it disappears:
combo_box_2.JPG
combo_box_2.JPG (12.94 KiB) Viewed 722 times
And I'm left with a flashing cursor in the text window. I can type value:
combo_box_3.JPG
combo_box_3.JPG (12.9 KiB) Viewed 722 times
But this isn't the behaviour I need. I only support list values, not custom entered value.

I'm sure I doing something ridiculous. Any advice is appreciated.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxComboBox::Clear() preventing selection from sticking?

Post by doublemax »

Hard to tell without seeing code or a running sample. My best guess is that after clearing and refilling the list, some code gets called that should not get called. Maybe because of a skipped event that should not get skipped? Just a wild guess.
Use the source, Luke!
buttonsrtoys
Experienced Solver
Experienced Solver
Posts: 58
Joined: Mon Jul 03, 2017 12:03 am

Re: wxComboBox::Clear() preventing selection from sticking?

Post by buttonsrtoys »

doublemax, thanks for the thoughts. It wouldn't surprise me if I'm calling something wrong as you say but am really just using the functions I mentioned in my OP, though maybe not in order?

I did find a workaround that suits my needs. Rather than using ::SetValue(..) to update the combobox, I find the index of the value I want to set in my list and then use ::SetSelection(..). Works great now.
Post Reply