I am trying to insert textbox1 + textbox2 = textbox3. And all my textboxes are set to selectAll(); while entering into textbox. So when I entered to textbox1 all the text will be in select mode and if I click backspace all data will be removed and an error occurring like
Input string was not in correct format
My code is
textBox3.Text = (int.Parse(textBox1.Text) + int.Parse(textBox2.Text)).ToString();`
I tried like
if (textBox1.Text != "")
{
textBox3.Text = (int.Parse(textBox1.Text) + int.Parse(textBox2.Text)).ToString();
}
In this case The value in the Textbox three is not changing when I click backspace. Means textbox will be null. That’s why value is not changing in thired textbox. Please help me. How could I ovecome this problem?
You are assuming that your inputs (
textBox1.TextandtextBox2.Text) are integers.If they are not,
int.Parsewill fail and give you the error you are seeing.You need to use
int.TryParse: