[Gtk-sharp-list] gtk.entry validation difficulty

Adam Tauno Williams adam at morrison-ind.com
Fri May 23 09:11:44 EDT 2008


> Here I found this short tutorial for restrict the input in a text
> entry only to numbers, quite useful.. maybe it's what are u looking
> for, it's in Spanish but I'm sure you can understand the code.., it
> also let you download a .tar.gz with the code.
> Link: http://www.developarts.com/limitar_la_captura_de_un_entry

Nice article,  only problem I see is that it negates the ability to
Tab / Shift-Tab to advance to the next or previous fields. 

I use -

[GLib.ConnectBefore]
protected virtual void OnEndKeyPressEvent (object o,
Gtk.KeyPressEventArgs args)
{
  if ((Array.IndexOf(dateChars, Convert.ToChar(args.Event.Key)) > -1) ||
      (args.Event.Key == Gdk.Key.BackSpace) ||
      (args.Event.Key == Gdk.Key.Tab) ||
      (args.Event.Key == Gdk.Key.ISO_Left_Tab))
  {
    args.RetVal = false;
    return;
  }
  args.RetVal = true;
} /* end OnEndKeyPressEvent */

- where Array dateChars = "1234567890-".ToCharArray();



More information about the Gtk-sharp-list mailing list