Page 1 of 1

wxComboBox::Clear() preventing selection from sticking?

Posted: Mon Jun 18, 2018 5:58 pm
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 724 times
but when return control to Wx, it disappears:
combo_box_2.JPG
combo_box_2.JPG (12.94 KiB) Viewed 724 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 724 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.

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

Posted: Mon Jun 18, 2018 6:38 pm
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.

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

Posted: Mon Jun 18, 2018 7:34 pm
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.