|
-
December 2nd, 2008, 10:29 PM
#1
this.controls not including the controls inside tabcontrol
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
-
December 3rd, 2008, 12:00 AM
#2
Re: this.controls not including the controls inside tabcontrol
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.
-
December 3rd, 2008, 07:07 AM
#3
Re: this.controls not including the controls inside tabcontrol
 Originally Posted by MadHatter
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.
 Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
-
December 3rd, 2008, 03:54 PM
#4
Re: this.controls not including the controls inside tabcontrol
this is the case for all of the container controls.
-
December 3rd, 2008, 05:11 PM
#5
Re: this.controls not including the controls inside tabcontrol
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;
}
}
}
-
December 3rd, 2008, 05:18 PM
#6
Re: this.controls not including the controls inside tabcontrol
Controls have a HasChildren property. Instead of explicitly checking for a tab control, just check the HasChildren property of each control.
-
December 3rd, 2008, 10:33 PM
#7
Re: this.controls not including the controls inside tabcontrol
Great! thank you...i will try it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|