Attached sample has two comboboxes, one use wx.CB_READONLY style the other does not.
When I do a SetValue and then a GetSelection the one with CB_READONLY style gives me the "right" value back were the other one gives me "-1".
Is this a known issue or do I miss something.
Werner
P.S.
My config is:
# Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)]
# wxPython 2.8.3.0, Boa Constructor 0.5.2
comboboxvista.py (2.78 KB)
Robin,
Robin Dunn wrote:
Werner F. Bruhin wrote:
Attached sample has two comboboxes, one use wx.CB_READONLY style the other does not.
When I do a SetValue and then a GetSelection the one with CB_READONLY style gives me the "right" value back were the other one gives me "-1".
Is this a known issue or do I miss something.
With the combobox value and selection are slightly different, but loosely coupled, things. You have the value of the textctrl, and also the selection of the drop-down list. When you select an item in the list then the value of the text changes, but it is possible to have a value that matches something in the list but was not selected from the list, so technically the value is not the same as the selection, they just happen to be equal. When you make a read-only combobox then that essentially means that the value can only be set by selecting an item from the list. I don't think that wx defines what should be done for keeping selections and values in sync, and just falls back on native behavior, which could very well be different for read-only and read-write controls.
In a nutshell, if you want to set the value based on the selection, then use SetSelection and GetSelection. If you don't care about the selection then use SetValue/GetValue. If it's read-only then you should probably stick with SetSelection/GetSelection because that more closely matches what the user is able to do.
Thanks for the detailed explanation.
As it is a maskedcombo I do this and it works nicely.
# use SetStringSelection to work for both readonly and writtable combo
comboBox.SetStringSelection(newAttr.ljust(comboBox._masklength))
Werner