I have an application with 20 textboxes, which they do get their values from a database when a selection is made in a combobox. I need to do the calculations (sum the textBoxes values) and display the result on label or in a textbox when the combobox selection is choosen.
I added the texBoxes into an array and then iterate through them. But I’m getting 0 as the result.
The Problem:

My Code:
private void sumTextBoxes()
{
TextBox[] txt;
txt = new TextBox[] { textBox1, textBox2, textBox3, textBox4, textBox5, textBox6, textBox7, textBox8, textBox9, textBox10 };
int value;
foreach (TextBox tb in txt)
{
if(tb !=null)
{
if (int.TryParse(tb.Text, out value))
{
if (textBox11.Text.Length > 0)
{
textBox11.Text = (int.Parse(textBox11.Text) + value).ToString();
}
else
textBox11.Text = value.ToString();
}
}
//label3.Text = Convert.ToString(value);
}
}
Where am I wrong? or a better way to solve it? PS: The textboxes on the left 1-10 and the total is 11 and on the right 12-21 total is 22