I'm trying to create a loop to avoid copy pasting these lines 30 times.
The names are:
- sum1 to sum30
- br1txt1 to br30txt1
- br1txt2 to br30txt2
//decimal sum30 = decimal.Parse(br30txt1.Text) + decimal.Parse(br30txt2.Text);
//sumTxt30.Text = sum30.ToString();
But the error I'm getting is that the textbox array seems to try to put the value of the textbox not the text box refrenc it self in to the array, how should I fix this?
private void sumX()
{
TextBox[] sumTextboxNames;
sumTextboxNames = new TextBox[29];
for (int i = 1; i < 31; i++)
{
if (sumTextboxNames[0] == null)
{
int y = 0;
foreach (Control c in this.Controls)
{
if (c is TextBox && c.Name.StartsWith("sum"))
{
sumTextboxNames[y] = (TextBox)c;
y++;
}
}
}
else
{
}
string1 = "br" + i + "txt" + 1 + ".Text";
string2 = "br" + i + "txt" + 2 + ".Text";
string3 = "sumTxt" + i + ".Text";
sum = decimal.Parse(string1) + decimal.Parse(string2);
int x = i - 1;
sumTextboxNames[x].Text = sum.ToString();
}
}