views:

619

answers:

3

There must be a better way than a constrained numeric updown control.

A: 

The MaskedTextBox might be of use. Failing that, I recommend using an ordinary TextBox with an OnTextChange event handler that checks to make sure the value entered is actually a number. Any non-numerical characters, and you can bang out a message box, or simply remove those characters completely, depending on your needs.

The NumericUpDown controls are slow to use sometimes, but they have intrinsic data validation which in some cases is quite useful. If the control is one the user is not going to use often, consider using it. Otherwise the MaskedTextBox or TextBox is the way to go.

Charlie Salts
The MaskedTextBox does not exist on the Mobile platform.
Henk Holterman
I suspected as much, hence why I added 'failing that.. '.
Charlie Salts
+6  A: 
MusiGenesis
intersting! +1 for that.
moster67
@moster67: it's my favorite hack of all time. This is a problem that vexed me horribly for years until I found this code.
MusiGenesis
Haha, very nice API magic, Thank you :)
Thanks. I'd be beaming with pride, if I had written it myself. :)
MusiGenesis
+1  A: 
MusiGenesis
Not useful for my current needs, but that is a really cool and inventive solution! If I could up-vote more than once, that would get a couple. :)
eidylon