Retrieving "invalid" value from a NumericUpDown Validating event
Posted
by alhazen
on Stack Overflow
See other posts from Stack Overflow
or by alhazen
Published on 2010-05-21T19:12:59Z
Indexed on
2010/05/21
20:20 UTC
Read the original article
Hit count: 547
When the user enters a value above numericUpDown.Maximum
, the control's value is automatically set to the maximum. I'd like to display a MessageBox when this occurs, but I'm not able to do that because control.Value
and control.Text
already contain the automatically set value, maximum, when Validating
event is raised.
private void numericUpDown_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
NumericUpDown control = sender as NumericUpDown;
decimal newValue = control.Value;
// decimal newValue;
// decimal.TryParse(control.Text, out newValue)
if (newValue > control.Maximum || newValue < control.Minimum)
{
// MessageBox
}
}
Thanks
© Stack Overflow or respective owner