简体   繁体   中英

Get content of all user controls from a flow layout panel

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

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM