Click to See Complete Forum and Search --> : this.controls not including the controls inside tabcontrol
yolip
December 2nd, 2008, 09:29 PM
Hi All,
I tried to get all the buttons in the working form using the code below, however, i found all the buttons in the Tabcontrol is not included in this.Controls. So how can i access all controls in a form?
foreach (Control childControl in this.Controls )
{
if (childControl is Button)
{
childControl.Enabled = inStatus;
}
}
Thanks
MadHatter
December 2nd, 2008, 11:00 PM
controls located on a tab are added to that tab's controls collection, not the form's control collection.
iterate over your tab control's tab pages property, and check each page's controls collection.
JonnyPoet
December 3rd, 2008, 06:07 AM
controls located on a tab are added to that tab's controls collection, not the form's control collection.
iterate over your tab control's tab pages property, and check each page's controls collection.Basically for knowing about where controls have been added, you can always look into the designer.cs of a form, because there you can read the code how your conrols are created and where they are added to. :wave:
eclipsed4utoo
December 3rd, 2008, 02:54 PM
this is the case for all of the container controls.
yolip
December 3rd, 2008, 04:11 PM
Thanks guys, i worked out this with following code. Cheers,
foreach (Control childControl in this.Controls )
{
if (childControl is TabControl)
{
foreach (Control ctlTabPage in childControl.Controls)
{
foreach (Control innerControl in ctlTabPage.Controls)
{
if (innerControl is Button)
{
innerControl.Enabled = inStatus;
}
}
}
}
else
{
if (childControl is Button)
{
childControl.Enabled = inStatus;
}
}
}
BigEd781
December 3rd, 2008, 04:18 PM
Controls have a HasChildren property. Instead of explicitly checking for a tab control, just check the HasChildren property of each control.
yolip
December 3rd, 2008, 09:33 PM
Great! thank you...i will try it
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.