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

Chris Howie cdhowie at gmail.com
Wed May 21 16:08:28 EDT 2008


(Whoops, sending to the list too.  Sorry, Jesper.)

On Wed, May 21, 2008 at 4:05 PM, Jesper K. Pedersen <linux at famped.dk> wrote:
> On Wed, 21 May 2008 15:52:22 -0400
> "Chris Howie" <cdhowie at gmail.com> wrote:
>
>> On Wed, May 21, 2008 at 3:48 PM, Jesper K. Pedersen <linux at famped.dk>
>> wrote:
>> > In connection with a small application I am writing I have run into
>> > a slight problem.
>> >
>> > I have a form consisting of several gtk.entry widgets and two
>> > buttons for "cancel" and "accept"
>> >
>> > Each gtk.entry needs data validated when it is edited (changed)
>> > meaning when you either press enter or try to deselect the entry (by
>> > for instance tab'ing/clicking on another entry) my program should
>> > validate the content of the entry... Except in the case where you
>> > press the "cancel" button which should just disregard all
>> > validation.
>> >
>> > Currently my software is running fine if users don't do anything
>> > but use "enter" to finalize data entry. I use the Entry.Activated
>> > handler to validate my input. Unfortunately we have users who are
>> > creative with using both the tabulate key and the mouse too.
>> >
>> > I have tried using the Entry.EditingDone handler but I cannot get
>> > the event to fire at all (the GUI is made in glade).
>> >
>> > I have also tried using the Widget.FocusOutEvent but then trying to
>> > press the "cancel" button will fire the validation event.
>> >
>> > Any idea's/suggestions on how to get around this problem?
>>
>> If validating the data isn't too resource-intensive (like CPU or DB
>> connection, etc) just do what I do: have all of the entries' Changed
>> signal call one method that validates the data and sets the Accept
>> button's Sensitive property accordingly.  Then users also get visual
>> feedback while they are typing.
>>
>> If this would be too slow then you could perform this validation when
>> an entry loses focus instead.
>>
>
> There is a slight problem with the resources as it is depending on a
> result from a database validation (a partnumber validation). Even with
> only approximately 19500 parts in the database it becomes a bit slow.
>
> The problem with using the FocusOutEvent is that it will force a
> validation even if the user try and cancel what he is doing by pressing
> the cancel button.
>
> I've tried checking if the widget that gets the new focus has it at the
> time of the previous Widget.FocusOutEvent - then I could just check for
> focus on the cancel button, but unfortunately focus isnt changed until
> the FocusOutEvent is done.
>
> Right now I am about ready to throw the mouse away and cut the tabulate
> key from the keyboard, but I think the whole problem is that I am the
> only programmer on the project and this is my first real project on
> C#/Gtk#

What would be wrong with just validating in the Clicked event for the
Accept button?

-- 
Chris Howie
http://www.chrishowie.com
http://en.wikipedia.org/wiki/User:Crazycomputers


More information about the Gtk-sharp-list mailing list