Pergunta

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;
}
Foi útil?

Solução

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);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top