Check if NumericUpDown is empty
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();