i have a windows form in which there are controls listed below
**panel1
button1
button2**
clicking on the button1 usercontrol is added on it, usercontrol can be added as much as the button is clicked means if the button1 is clicked one times then one user contorl will be added and if usercontrol is clicked twice then 2 usercontrol is added
usercontrol contains 4 controls
combobox1
combobox2
textbox1
textbox2
i want to add the text of textbox2 of all the dynamically generated usercontrol control and set to a label on the winform how can i do that?
i have tried this code
foreach (Control ctrl in panel1.Controls)
{
if (ctrl is UserControl)
{
UserControl1 myCrl = ctrl as UserControl1;
int g;
g += Convert.ToInt32(myCrl.textbox2.Text);
this doesnt happen an error is coming
}
}
how to get sum of all the dynamically generated control's text!