0

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;
}
John Saunders
  • 160,644
  • 26
  • 247
  • 397
Nurdism
  • 578
  • 1
  • 9
  • 20

1 Answers1

1

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);
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321