SetValue and SetStringSelection in a wxComboBox

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
Knows some wx things
Knows some wx things
Posts: 42
Joined: Wed May 24, 2006 2:38 pm

SetValue and SetStringSelection in a wxComboBox

Post by kayamel » Tue Apr 29, 2008 4:33 pm


I'm facing a problem when using SetValue in a combobox.
In my code i define a wxArrayString for the combobox.

Code: Select all

wxArrayString cb_multiply;

combo = new wxComboBox( itemPanel1, ID_CB_MULTIPLICATEUR_PTS, _("1"), wxDefaultPosition, wxSize(50, -1), cb_multiply, wxCB_DROPDOWN );
If I use

Code: Select all

combo.SetStringSelection(_("2")); //Or any other value in the list

Code: Select all

Everything works fine. I have the right index

If I use SetValue() in place of SetStringSelection(), it does not work. The selection stays at the first choice and I get a -1 when I try to get the index.

I'd like to know if anyone else is experiencing the same problem or if it's just me who's got mixed up in my code.

I spent an awful a lot of time trying to figure out what was wrong with my code due to this.
The fact that SetValue is documented in the 2.8.7 manual and SetStringSelection is not did not help.


Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Sep 02, 2006 7:24 pm
Location: Ukraine

Post by lester » Tue Apr 29, 2008 6:05 pm

You can use such code:

For set value:

int selection = combo->FindString( _("2") );
if( selection != wxNOT_FOUND )
combo->SetSelection( selection );
combo->SetValue( _("2") );


For get selection:

int selection = combo->FindString( _("2") );

That's ugly but must work

Post Reply