numeric up-downs and enforcing the range

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I just noticed that a numeric up/down will let you manually type in any
number even if it is beyond the min/max range you specified.
The control will not actually return this value if it is beyond the min/max
but it won't give you any indication that the value you typed in is out of
range.
Any way to get around this so a user typing in a number out of range will
get some kind of warning ?
 
Trap it in the Validating event or do range checking when the value changes
and set it back to something sensible.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
That's odd, I set an onValidating event and was going to do a range check on
the value and do whatever fix necessary when I realized once I set the event
and called Value property on the numeric up down, it automatically changes
the text to fit in the range... so my event just looks like this:

private void onValidatingUpDown(object sender,
System.ComponentModel.CancelEventArgs e) {

NumericUpDown control = sender as NumericUpDown;
decimal value = control.Value;
}

and that's it... guess the Value property does the range check?
 
Back
Top