1
votes

I have a user control which has a label and a text box. The text box gets the values dynamically at run time. There are n number of dynamic user controls added as shown below:

for loop
{
   MyUserControl control = new MyUserControl();
   control.SetLabelValue(label);
   control.SetTextBoxValue(text);
   flowLayoutPanel.Controls.Add(control);
} 

flowLayoutPanel is my flow layout panel and SetLabelValue() and SetTextBoxValue() are methods in the user control class to add value to the controls. So lets say in the panel 10 such controls are added. Is there any way i can get the value(text) of all the text boxes which have been added?

Thanks

1

1 Answers

1
votes

Use Linq. Substitute c.Text with whatever you use to get at the Value of one of your MyUserControls:

List<String> values = new List<String>();
foreach (MyUserControl c in flowLayoutPanel.Controls.OfType<MyUserControl>())
    values.Add(c.Text);