Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

Validating Integer Problems....

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TheSteph - 09 Nov 2006 17:41 GMT
Hi Experts !

I have a Winform Program in C# / .NET 2.0

I would like to ensure that a value in a TextBox is a valid Int32 when user
get out of it (TextBox loose focus)

BUT : The "Validating" Event of a TextBox does NOT fire when user click on
controls like ToolStripButton, ToolStripMenu,.. (in fact Validating event is
fired AFTER the Click event of the ToolStripButton, so it's too late to
check...)

In this kind of case, does it mean that a programmer using .NET MUST check
at more than one place that the value in a given TextBox is a valid Integer
? (Once in the validating event, and Once in EACH ToolStripButton(menu,..)
Click) ???

If no : HOW CAN I DO to check if a TextBox have a valid Int32 value when
TextBox loose focus AND when user click on a ToolStripButton (or menu)
?????????

If yes : How can MS think that it's a good programming practice and modern
to check the same basic and simple thing at different places in the same
form. Why this kind of problem in the "Third version of their very last
programming language"  ?

Any solution is welcome and will save me a lot of headache..

Steph
ignacio machin - 09 Nov 2006 21:36 GMT
I would go in a different direction, I will not let the user enter
non-numeric values

There are several ways of doing this and IIRC in 2.0 you have something to
force this.

Anyway, you can use the KeyDown event to reject the invalid keys.

additionally you can derive from Textbox and override CreateParams

> Hi Experts !
>
[quoted text clipped - 25 lines]
>
> Steph
TheSteph - 10 Nov 2006 10:50 GMT
> Anyway, you can use the KeyDown event to reject the invalid keys.

 All sample code I found accept numbers like 9999999999 that are build from
correct keys but are not valid Int32 values...

 Moreover I have some "encoding helper" job to do while validating the
final value : Example : 12,3456,789.25 should be accepted and transformed to
123.456.789,25 ( "," is decimal sep here).  This kind of things can be done
only at Validating time. hence the problem remains with controls like
ToolStripButtons.

 The things I can't understand is that Controls have a Validating event
that is not guaranteed to be fired when user click on other controls (like
ToolStripButton,.)...unbelivable... Imagine a click event on a control that
is not guaranteed to be fired when user click the control. unreliable so
unusable from a professional standpoint..

Thanks for your help,  I keep searching a validating solution.  The best is
maybe to wait until VS "Hawaii" to be done...

Steph.

> I would go in a different direction, I will not let the user enter
> non-numeric values
[quoted text clipped - 35 lines]
> >
> > Steph
ignacio machin - 10 Nov 2006 15:29 GMT
Hi,

What make u think that it will be different in "hawaii" ?
you can do validation in the KeyDown, the ugliest one would be trying to
convert it to Int32 and handling the exception.

Take a look at CausesValidation  though.

> > Anyway, you can use the KeyDown event to reject the invalid keys.
>
[quoted text clipped - 64 lines]
> > >
> > > Steph

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.