How to force a numeric textbox control not to accept empty string?

1.5k Views Asked by At

I have a winform app.

I am using a numeric textbox control. My problem is that I can erase the value and leave the control. When I do that - the value that was before I delete it is the value of the control, but the display is an empty value. It is important to mention - The default value of the controls is 0. I would like that if the user deletes the value of the control , I would like to set the value of the control to 0.

My question is :

How can I force a numeric textbox control not to display an empty value ??

Thanks .

1

There are 1 best solutions below

5
Parimal Raj On

well, you can write a simple validation

private void textBox1_TextChanged(object sender, EventArgs e)
{
    if (String.IsNullOrEmpty(textBox1.Text))
    {
        textBox1.Text = "0";
    }
}