wxComboBox and a validator

53 views
Skip to first unread message

Ilia Kats

unread,
Feb 26, 2003, 6:36:48 AM2/26/03
to wxpytho...@lists.wxwindows.org
Hi all,

I had created a wxComboBox and I want the text entered in the combobox to be limited to numeric only. I don't want to do this via the EVT_TEXT event, but via a validator. In other words I want to do this through the EVT_CHAR event handled in the validator. I tried to do the same thing as shown in the demo (in the validor example) but with no success. What should I do?

Thanx for your help.

Robin Dunn

unread,
Feb 26, 2003, 6:39:54 PM2/26/03
to wxPytho...@lists.wxwindows.org

Give more details and perhaps a working sample that shows the problem.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Will Sadkin

unread,
Feb 27, 2003, 11:44:37 AM2/27/03
to wxPytho...@lists.wxwindows.org
> Ilia Kats wrote:
> > Hi all,
> >
> > I had created a wxComboBox and I want the text entered in the
> > combobox to be limited to numeric only. I don't want to do this via
> > the EVT_TEXT event, but via a validator. In other words I want to do
> > this through the EVT_CHAR event handled in the validator. I tried to
> > do the same thing as shown in the demo (in the validor example) but
> > with no success. What should I do?

In my experience, validators can be tricky to get right. You can try
looking at the implementation of wxIntCtrl in wxPython2.4.0.2
(lib/intctrl.py); I wrote this to do the same thing you want, but
in a wxTextCtrl rather than the wxComboBox. The semantics, however,
should be similar.

Alternatively, Jeff Childers and I are working on a set of masked
edit controls, including a wxMaskedComboBox that should also be
able to do what you want. It allows you to do validation on the
text such that the value entered must be a number, and allows you to
additionally verify that the number entered is one of the values
in the choice list. We hope to have the classes ready for
submission soon, so if you can afford to wait until the next
wxPython release, you can use that. I presume there's a finite
list of valid numeric choices for your application?

Regards,
/Will Sadkin
Parlance Corporation

Reply all
Reply to author
Forward
0 new messages