Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Problems with the NumericUpDown Control

I have been testing with this control and I have discovered what i think is a bug.

Drop one on a form.  Set the MinValue to 0 and the MaxValue to 10.

Run and enter 11 into the control with the keyboard.

The control lets you enter 11 and actually displays 11.

I handled the key down on the control to see whats going on.  I get this exception:

Exception Type: System.ArgumentException

Message: '10' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'.

When looking at the Value property and 11 has been keyed in.

So, we can limit user input with the click and scroll, but not through the keyboard?  Why even provide a Min and max Value then?   

 

3 Comments

  • I tried this, though I didn't get an exception, but yes it did let me enter 11 .. although the controlname.value was always 10D.



    Though it is sorta weird that it lets you enter an 11 and shows 11 (even though the value was 10).



    But I didn't get any exceptions !!

  • You only get an exception if you try to work with the text (I was trying to cast it to the Value).



    I found a workaround. If the value entered is greater than the Maximum, the Value is set to the Maximum. If its less than the Minimum, its set to the Minimum. I simpy handle the Validating event and set the Test property to the Value property all the time. So, if the Max is 9 and the Min is 0 and then user enters 11, they will see 9, which is what the value is set to.

  • Hi,
    I just found this same bug.
    I had the same idea as yourself, of checking if the entered value is greater than Maximum, or less than Minimum.
    But when stepping through the code, the value shows as = to the Maximum or Minimum already.
    However, just the presence of that code makes it go to the allowable value - weird!
    Even just doing:
    Dim decVal As Decimal = nudSetNumber.Value()
    lets the control set the displayed value to the allowable value....

Comments have been disabled for this content.