Page 1 of 1

SetValue and SetStringSelection in a wxComboBox

Posted: Tue Apr 29, 2008 4:33 pm
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

Posted: Tue Apr 29, 2008 6:05 pm
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