Retaining selected value in wx.ComboBox

I found an earlier message this month about using wx.ComboBox.Clear() and wx.ComboBox.AppendItems() to reconstruct a combo box at run-time after the original creation.

However, I'm reconstructing this ComboBox menu (along with a few adjacent ones) as the result of selecting a ComboBox item from the previous set of values in the list. After I do a .Clear() and .AppendItems(), I'm trying to use .SetValue() to set the "default" contents of the input text field, i.e.:

ComboBox1.Clear()
ComboBox1.AppendItems(ListOfItems1)
ComboBox1.SetValue(SelectedItem1)

(SelectedItem in ListOfItems) == True, so that shouldn't be an issue.

The problem: SelectedItem isn't displayed in ComboBox1's text field, at least not immediately. If I go through another iteration of .Clear(), AppendItems(), and SetItem() for this ComboBox1 (due to a selection in a separate, but adjacent ComboBox2), i.e.:

ComboBox1.Clear()
ComboBox1.AppendItems(ListOfItems1)
ComboBox1.SetValue(SelectedItem1)

ComboBox2.Clear()
ComboBox2.AppendItems(ListOfItems2)
ComboBox2.SetValue(SelectedItem2)

Now, ComboBox1 will display SelectedItem1 in the text field, but ComboBox2 will not display SelectedItem2.

I tried using .Paste() instead of .SetValue(), and although I can see the text (briefly) pasted into the text field, it disappears quickly thereafter.

If I actually enter text into the field and hit enter (invoking the handler bound to wx.EVT_TEXT_ENTER), the entered data remains in the text field.

If I change the style from wx.CB_DROPDOWN to wx.CB_READONLY, the problem goes away. I can select something in the list and it will remain in the text box.

Is there something I can do to either preserve or restore the string from the previous selection, so that it remains in the input text box?

Try using SetSelection(index) where index is the index number of the
item you want to show up.

ยทยทยท

On 6/28/05, Paul Barnett <wxpython@ptb.org> wrote:

I found an earlier message this month about using wx.ComboBox.Clear()
and wx.ComboBox.AppendItems() to reconstruct a combo box at run-time
after the original creation.

However, I'm reconstructing this ComboBox menu (along with a few
adjacent ones) as the result of selecting a ComboBox item from the
previous set of values in the list. After I do a .Clear() and
.AppendItems(), I'm trying to use .SetValue() to set the "default"
contents of the input text field, i.e.:

ComboBox1.Clear()
ComboBox1.AppendItems(ListOfItems1)
ComboBox1.SetValue(SelectedItem1)

(SelectedItem in ListOfItems) == True, so that shouldn't be an issue.

The problem: SelectedItem isn't displayed in ComboBox1's text field, at
least not immediately. If I go through another iteration of .Clear(),
AppendItems(), and SetItem() for this ComboBox1 (due to a selection in a
separate, but adjacent ComboBox2), i.e.:

ComboBox1.Clear()
ComboBox1.AppendItems(ListOfItems1)
ComboBox1.SetValue(SelectedItem1)

ComboBox2.Clear()
ComboBox2.AppendItems(ListOfItems2)
ComboBox2.SetValue(SelectedItem2)

Now, ComboBox1 will display SelectedItem1 in the text field, but
ComboBox2 will not display SelectedItem2.

I tried using .Paste() instead of .SetValue(), and although I can see
the text (briefly) pasted into the text field, it disappears quickly
thereafter.

If I actually enter text into the field and hit enter (invoking the
handler bound to wx.EVT_TEXT_ENTER), the entered data remains in the
text field.

If I change the style from wx.CB_DROPDOWN to wx.CB_READONLY, the problem
goes away. I can select something in the list and it will remain in the
text box.

Is there something I can do to either preserve or restore the string
from the previous selection, so that it remains in the input text box?

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

--
Don't be a pioneeer. A pioneer is the guy with the arrow through his
chest. -- John J. Rakos