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.
kayamel
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 »

Hi,

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;
    cb_multiply.Add(_("1"));
    cb_multiply.Add(_("2"));
    cb_multiply.Add(_("4"));
    cb_multiply.Add(_("8"));

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
then

Code: Select all

combo.GetCurrentSelection();
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.

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

Post by lester »

You can use such code:

For set value:

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

....

For get selection:

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

That's ugly but must work