简体   繁体   中英

Access Dynamically Created Controls in a TabPageControl

I am creating a bunch of UserControls each in a tab in a TabControl. The problem I'm having is I need to access a value from the controls. I have no idea how to do this.

string q;
foreach (TabPage tp in tabControler.TabPages)
{
    Filter f = tp.Controls.Find("Filter",true); //not working at all.
    q += f.querry;
}

When creating your control, add the name to it:

Filter Filter1 = new Filter();
Filter1.Name = "Filter1";

If this is WinForms and Filter1 is the name of the Filter control, it would just be:

if (tp.Controls.ContainsKey("Filter1"))
{
  Filter selectedFilter = (Filter)tp.Controls["Filter1"];
} 
Debug.Write(selectedFilter.Value);

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