i can iterate through the controls which are on panel by this two code
Form4 fl = new Form4();
StringBuilder sb = new StringBuilder();
foreach (Control c in panel1.Controls)
{
if (c is ComboBox)
{
ComboBox cb = (ComboBox)c;
sb.Append(cb.Text);
fl.comboBox1.Text = sb.ToString();
fl.Show();
}
}
OR by this
List lst = new List();
void GetComboBoxValues()
StringBuilder sb = new StringBuilder();
{
sb.Append(c.Text + "\r\n");
}
MessageBox.Show(sb.ToString());
}
but i add a panel and on panel a usercontrol which contains a combobox and textbox how that can be possible to find controls and add to the string builder
so i thought iterating through usercontrol and finding the text and adding it to the string builder,is that possible?
Responding to the comment left for L.B’s answer. Personally I believe L.B’s answer is the easiest and requires the least amount of coding, the best thing is it will find all the controls of a specific type on a panel no matter how nested they are(imagine if you have a user control inside a user control).
Just copy the
FindControlsmethod from LB’s answer to your solution as is and where you need to loop through the controls of the panel, do something like this:A simple example would be something like this, but be warned that it will not work if you have a case of a user control inside a user control, so I would strongly suggest going with LB’s example: