Results 1 to 8 of 8

Thread: [RESOLVED] Children of tabcontrol

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2011
    Posts
    152

    Resolved [RESOLVED] Children of tabcontrol

    I'm using this subroutine to recursively toggle disabled/invisible state for a control and its children:

    Code:
        Public Sub ConcealObject(ByVal Parent As Control)
                For Each C As Control In Parent.Controls
                    'conceals the control
                If C.Enabled = False OrElse C.Visible = False Then
                    If CStr(C.Tag) <> "noconceal" Then 'a tag that are either never disabled or never hidden and thus shouldn't be toggled
                        Conceal(C)
                    End If
                ElseIf C.HasChildren Then
                    ConcealObject(C) 'repeats the loop at the next level down (will keep repeating for as many levels as there are)
                    'NOTE: This can't turn into an endless loop because it's always going down a level and control inheritance can't be cyclical
                End If
            Next C
        End Sub
    This works for everything except tabcontrols. On a tabcontrol, it hides/disables the correct fields on the front tabpage, but not any of the other pages. If I click on a different tabpage and then run the subroutine, it will hide/disable the controls on that page correctly, but that page only. How can I make it run through all the controls on all the tab pages every time?

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Children of tabcontrol

    Not sure why you'd need to, to be honest, as the contents of a tabpage other than the current one are de facto invisible and you could change the settings on page selection. However, your problem is that your failing to appreciate the relationships in a Tab Control

    Tab Control = Parent
    TabPages = Child of TabControl & Parent of page controls
    Controls on tabpage = child of TabPage, grandchild of TabControl
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2011
    Posts
    152

    Re: Children of tabcontrol

    I fully appreciate the relationships in a tab control, but the subroutine is recursive, so it applies to children, grandchildren, great-grandchildren, great-great-grandchildren, etc.

    And why does it work correctly for the current tab, but not for any of the others? Inheritance ought to be the same for all of them, and the others still have a visible state of true even when you can't see them.
    Last edited by colleen.boye; May 24th, 2013 at 04:51 PM. Reason: clarification

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Children of tabcontrol

    and the others still have a visible state of true even when you can't see them.
    Er .. no they don't. TabPages don't have a Visible property at all (well not a public one, anyway). But then I can't see how your Sub works at all. If the control is not visible you call Conceal() which does what? Toggles back to visible (in spite of its name)? If the control is visible and has children then it goes around again until the children run out. So what happens to a control that is visible but has no children (the last in the line of recursions)? Nothing as far as I can see. I can see where invisible controls might get restored to visibility but I can't for the life of me fathom where visible controls get turned invisible.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    Re: Children of tabcontrol

    you can't set properties or interact with controls on an unselected tabpage.
    for instance, if you have a button on an unselected tabpage, calling .PerformClick doesn't work...

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Children of tabcontrol

    It "works" because the TabControl's child is the active tabpage... the rest of the tabpages are in the TabPages collection... which is why it doesn't also do the other pages... they're not in the child.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Children of tabcontrol

    you can't set properties or interact with controls on an unselected tabpage.
    Say what now? It wouldn't be much use as a control if you couldn't change properties of pages and their controls while they were unselected. Interaction such as Click, I grant you.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Oct 2011
    Posts
    152

    Re: Children of tabcontrol

    If the control is not visible you call Conceal() which does what?
    It switches it to being visible but disabled:

    Code:
        Public Sub Conceal(ByVal concealedObject As Object)
            'either hides or disables the object depending on the setting
            If HideDisabled = True Then
                concealedObject.Visible = False
                concealedObject.enabled = True
            Else
                concealedObject.Enabled = False
                concealedObject.visible = True
            End If
        End Sub
    I added this because my primary user keeps trying to click on disabled buttons

    It "works" because the TabControl's child is the active tabpage... the rest of the tabpages are in the TabPages collection... which is why it doesn't also do the other pages... they're not in the child.
    That makes a lot of sense, but I tried this:

    Code:
            For Each page As Control In tbEntry.Controls
                MessageBox.Show(page.Name)
            Next
    And it returned all the pages. But dunfiddlin was right that they don't count as visible (my mistake there). So I fixed it by just adding a special case for tabpages:

    Code:
        Public Sub ConcealObject(ByVal Parent As Control)
            For Each C As Control In Parent.Controls
                'conceals the control if necessary
                If (C.Enabled = False OrElse C.Visible = False) AndAlso Not TypeOf C Is TabPage Then
                    If CStr(C.Tag) <> "noconceal" Then 'a tag that are either never disabled or never hidden and thus shouldn't be toggled
                        Conceal(C)
                    End If
                ElseIf C.HasChildren Then
                    If TypeOf C Is TabPage Then
                        C.Show()
                    End If
                    ConcealObject(C) 'repeats the loop at the next level down (will keep repeating for as many levels as there are)
                End If
            Next C
        End Sub
    This fixes the visibility problem; unfortunately it leaves a different (apparently unrelated) problem that I'd better make a new thread for.

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