NumericUpDown ignores Minimum/Maximum

C

Christoph Nahr

Everyone knows by now that the NumericUpDown control does not fire the
ValueChanged event when the user has manually entered a value.

However, I just discovered that manually entered values are also never
restricted to the Minimum and Maximum values, not even when the user
tabs away from the control!

The attached sample program creates a NUD control with a value range
of 1-10, and a button whose sole purpose is to allow tabbing away from
the NUD control. Note that you can manually enter whatever value you
want, and the value will persist even after tabbing back and forth.

The only workaround that I've found is to attach a Validating event
handler that cancels any change that would cause the value to leave
the range defined by Minimum and Maximum.

Is there some secret trick that I'm missing? Thanks...

----- C# sample code follows -----

using System;
using System.Drawing;
using System.Windows.Forms;

public class WindowsForm: Form {

public static void Main() {
Application.Run(new WindowsForm());
}

public WindowsForm() {

NumericUpDown upDown = new NumericUpDown();
upDown.Location = new Point(10, 10);
upDown.Minimum = 1m;
upDown.Maximum = 10m;
Controls.Add(upDown);

Button button = new Button();
button.Location = new Point(upDown.Right + 10, 10);
button.Text = "OK";
Controls.Add(button);
}
}
 
H

Herfried K. Wagner [MVP]

* "=?Utf-8?B?TWlrZSBpbiBQYXJhZGlzZQ==?= said:
There is a bug which I think is what you are talking about ...

MicroSoft KB#814347 Bug in numeric updown.

Online link:

BUG: The Value in the NumericUpDown Control Does Not Reset to the Maximum or
Minimum Value If You Use the TAB Key or Mouse to Shift Focus
<URL:http://support.microsoft.com/?id=814347>
 
C

Christoph Nahr

There is a bug which I think is what you are talking about ...

MicroSoft KB#814347 Bug in numeric updown.

Thanks, that's the one! But why does it say "Beta Information"?
Looks like someone forgot to update the page...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top