Forum: wxRuby numeric textbox

2aa32559134aa3d596fb749f8ffccde7?d=identicon&s=25 hendra kusuma (Guest)
on 2010-04-06 11:14
(Received via mailing list)
Dear all,

what is a good way to implement a textbox that can only receive number?
when I tried to implement it using text_updated event
it runs so slow that it disturb overall process (my menu stop working)
or even better, what method to overwrite in wxtextctrl class to achieve
the
goal?

Regards
Hendra
06f6780c99d4a8dd71f2b474082ea9ce?d=identicon&s=25 Alex Fenton (Guest)
on 2010-04-06 13:05
(Received via mailing list)
Hi Hendra

hendra kusuma wrote:
> what is a good way to implement a textbox that can only receive number?

The best way is to use Validators. There's a pre-built one for
controlling numerics:

Wx::TextCtrl.new(parent,
  :validator => Wx::TextValidator.new(Wx::FILTER_NUMERIC) )

cheers
alex
2aa32559134aa3d596fb749f8ffccde7?d=identicon&s=25 hendra kusuma (Guest)
on 2010-04-07 05:52
(Received via mailing list)
On Tue, Apr 6, 2010 at 6:04 PM, Alex Fenton <alex@pressure.to> wrote:

>
> Wx::TextCtrl.new(parent,
>  :validator => Wx::TextValidator.new(Wx::FILTER_NUMERIC) )
>

I tried filter_numeric before
and found out if it only filter input, not realy confirm if the number
correct
I try to workaround a bit using key_update event
and filter some more key like + - , . e
well, it works well, the trick is to use* change_value*, not *set_value*
somehow, when I try to add humanizing number function, I got stuck
(humanizing = 10000 -> 10,000)
because I cannot move my cursor / insert point to the last of textctrl
and *set_insertion_point_end* does not seem to work
is there a way to fix this?
This topic is locked and can not be replied to.