SetSelection() on wx.ComboBox

1,848 views
Skip to first unread message

beppe

unread,
Sep 14, 2012, 11:14:56 AM9/14/12
to wxpytho...@googlegroups.com
hi all,
even if in the documentation I have not found it I have seen that among the methods of wx.ComboBox I can use SetSelection().
It works until use values as 1,2,3 but if I put -1 ,that is I try to set the combo on any intems, 
it doesn't work but not even me return an error.
I would want to do this because I have noticed that just wx.ComboBox is created the value of GetCurrentSelection() is -1 and there is no
items select.
I believed whether to return to this state I was able to set the current selection to -1 using SetSelection().



self.cbDepartments.SetSelection(-1)

where self.cbDepartments is 

self.cbDepartments = wx.ComboBox(panel,ID_DEPARTMENTS,
                                       size = (100, -1),
                                       choices = '',
                                       style = wx.CB_READONLY|wx.CB_DROPDOWN)
                                       
the combo is fed by records(tuple) extracted by a database.
I'm on debian.

suggestions?
regards
beppe

beppe

unread,
Sep 14, 2012, 11:40:04 AM9/14/12
to wxpytho...@googlegroups.com
I add a simple app  
simple_app.py

Mike Driscoll

unread,
Sep 14, 2012, 11:45:00 AM9/14/12
to wxpytho...@googlegroups.com
Hi,

You just need to add a blank string as the first choice in your list of choices. The -1 is a special number that can mean a lot of different things in wxPython, so that won't work.

- Mike

beppe

unread,
Sep 14, 2012, 12:10:50 PM9/14/12
to wxpytho...@googlegroups.com
Since the SetSelection(-1) works well and I need to read the current selection  I have resolved adding 
self.cbDepartments.SetValue('')
to force the combo to show a blank string.
I add a new simple app to clarify my purpose.
thanks mike.

simple_app.py

C M

unread,
Sep 14, 2012, 1:31:39 PM9/14/12
to wxpytho...@googlegroups.com
Since the SetSelection(-1) works well and I need to read the current selection  I have resolved adding 
self.cbDepartments.SetValue('')
to force the combo to show a blank string.
I add a new simple app to clarify my purpose.
thanks mike.

A user experience suggestion: 

Instead of having a blank string to signify to the user "no selection", what I do is make a string that gives the user some information about what that comboCtrl is for, such as "Choose a selection..." and then I use that string to .SetValue() on the comboCtrl, and revert to that whenever things get reset.  Sometimes the string can be even more specific than that, such as "Choose a provider...", "Choose or enter a customer name...", "Choose or enter a starting bid....", etc.

This way, the control is its own label and there is (sometimes) no need to also have a staticText next to or above it to indicate its purpose.

Che
Reply all
Reply to author
Forward
0 new messages