Re: [wxpython-users] SetMaxLength for ComboBox
by Phil Mayes other posts by this author
May 8 2008 12:03PM messages near this date
Re: [wxpython-users] SetMaxLength for ComboBox
|
RE: [wxpython-users] SetMaxLength for ComboBox
At 09:15 AM 5/8/2008, Robin Dunn wrote:
> Phil Mayes wrote:
> >Hi all,
> >I want to limit the number of characters typed into the text field of a
> >CB_DROPDOWN ComboBox. I thought I had seen a way of getting the TextCtrl
> >so I can apply SetMaxLength(), but can't find any references to it in
> >the archives.
>
> Unfortunately there isn't a built-in way to do tha with a combobox. You'll
> have to catch events (EVT_CHAR and/or maybe EVT_TEXT) and impose the limit
> yourself.
Thank you Robin, that works well:
def OnTextValue(self, evt):
"""User has inserted text into combo box;
check that maximum length is not exceeded
"""
wnd = evt.GetEventObject()
s = wnd.GetValue()
over = len(s) - self.valueLength
if over > 0:
n = wnd.GetInsertionPoint()
m = n - over
wnd.SetValue(s[:m] + s[n:])
wnd.SetInsertionPoint(m)
_______________________________________________
wxpython-users mailing list
wxpython-users@[...].org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
Thread:
Phil Mayes
Robin Dunn
Phil Mayes
Kyle W Rickey
Robin Dunn
|