CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2002
    Location
    Australia
    Posts
    207

    Unhappy 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

  2. #2
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    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.

  3. #3
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: this.controls not including the controls inside tabcontrol

    Quote Originally Posted by MadHatter View Post
    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

  4. #4
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: this.controls not including the controls inside tabcontrol

    this is the case for all of the container controls.

  5. #5
    Join Date
    Oct 2002
    Location
    Australia
    Posts
    207

    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;
    }
    }
    }

  6. #6
    Join Date
    Jun 2008
    Posts
    2,477

    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.

  7. #7
    Join Date
    Oct 2002
    Location
    Australia
    Posts
    207

    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
  •  





Click Here to Expand Forum to Full Width

Featured