TabPages controls created on the fly [modified]
-
I am creating TabPages dynamically, adding a few textboxes, buttons etc. I can't figure out though how to access these controls. I tried:
foreach (TabPage tp in tabControl1.TabPages)
{
foreach (Control c in tp)
{
if (c is CheckBox)
{
if (c.Enabled == true)
MessageBox.Show ("Enabled");
}
}
}but get the error that TabPage does not contain a definition for GetEnumerator(). As the controls are created dynamically, I can't access them by name in the code. Any ideas on how to access these controls? -- modified at 4:06 Thursday 11th October, 2007
-
I am creating TabPages dynamically, adding a few textboxes, buttons etc. I can't figure out though how to access these controls. I tried:
foreach (TabPage tp in tabControl1.TabPages)
{
foreach (Control c in tp)
{
if (c is CheckBox)
{
if (c.Enabled == true)
MessageBox.Show ("Enabled");
}
}
}but get the error that TabPage does not contain a definition for GetEnumerator(). As the controls are created dynamically, I can't access them by name in the code. Any ideas on how to access these controls? -- modified at 4:06 Thursday 11th October, 2007
That sounds odd, I would have thought what you're doing is fine. Try changing the outer loop from a foreach to a standard for loop. The implication is that the TabPages collection does not implement IEnumerable.
Regards, Rob Philpott.
-
I am creating TabPages dynamically, adding a few textboxes, buttons etc. I can't figure out though how to access these controls. I tried:
foreach (TabPage tp in tabControl1.TabPages)
{
foreach (Control c in tp)
{
if (c is CheckBox)
{
if (c.Enabled == true)
MessageBox.Show ("Enabled");
}
}
}but get the error that TabPage does not contain a definition for GetEnumerator(). As the controls are created dynamically, I can't access them by name in the code. Any ideas on how to access these controls? -- modified at 4:06 Thursday 11th October, 2007
we can do like the following one... foreach (TabPage tp in tabControl1.TabPages) { for (int i = 0; i < tp.Controls.Count;i++) { if (tp.Controls[0] is CheckBox) { if(((CheckBox)(tp.Controls[0])).Enabled) MessageBox.Show ("Enabled"); } } }
Koushik
-
I am creating TabPages dynamically, adding a few textboxes, buttons etc. I can't figure out though how to access these controls. I tried:
foreach (TabPage tp in tabControl1.TabPages)
{
foreach (Control c in tp)
{
if (c is CheckBox)
{
if (c.Enabled == true)
MessageBox.Show ("Enabled");
}
}
}but get the error that TabPage does not contain a definition for GetEnumerator(). As the controls are created dynamically, I can't access them by name in the code. Any ideas on how to access these controls? -- modified at 4:06 Thursday 11th October, 2007
oh yes, just spotted it. its this :
foreach (Control c in tp)
should be;foreach (Control c in tp.Controls)
or something like that. Can't remember what the collection is called.Regards, Rob Philpott.
-
oh yes, just spotted it. its this :
foreach (Control c in tp)
should be;foreach (Control c in tp.Controls)
or something like that. Can't remember what the collection is called.Regards, Rob Philpott.
Thanks guys, the
foreach (Control c in tp.Controls)
was what I needed.