How do I check whether the user left a NumericUpDown
control empty, removing the value on it?
So I can reassign it a value of 0.
if(NumericUpDown1.Text == "")
{
// If the value in the numeric updown is an empty string, replace with 0.
NumericUpDown1.Text = "0";
}
It might be useful to use the validated event and ask for the text property
private void myNumericUpDown_Validated(object sender, EventArgs e)
{
if (myNumericUpDown.Text == "")
{
myNumericUpDown.Text = "0";
}
}
Even if the user deleted the content of the numericUpDown
control, its value still remains.upDown.Text
will be "", but upDown.Value
will be the previous valid value entered.
So my way to 'prevent' the user to leave the control empty, on the onLeave
event, I set:
upDown.Text = upDown.Value.ToString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With