I am trying to Loop through the tabpages of a tabcontrol in c#. Each tabpage has multiple textboxes. The purpose is to sum up all of the values of these textboxes.
double sum = 0;
foreach(TabPage tbp in tabControl1.TabPages)
{
foreach(System.Windows.Forms.Control c in tbp.Controls)
{
if (c.ToString() == "TextBox")
{
sum += Convert.ToDouble(c.Text);
}
}
}
When I execute this code, the first foreach loop is entered three times even though I have one TabPage in my TabControl. Furthermore, the if statement is not entered, so there seems to be something wrong with that as well.