SetSelection() on wx.ComboBox

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

I add a simple app

simple_app.py (2.61 KB)

···

Il giorno venerdì 14 settembre 2012 17:14:56 UTC+2, beppe ha scritto:

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

Hi,

···

On Friday, September 14, 2012 10:14:56 AM UTC-5, beppe wrote:

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

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

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 (2.78 KB)

···

Il giorno venerdì 14 settembre 2012 17:45:01 UTC+2, Mike Driscoll ha scritto:

Hi,

On Friday, September 14, 2012 10:14:56 AM UTC-5, beppe wrote:

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

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

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