|
-
May 24th, 2013, 04:22 PM
#1
Thread Starter
Addicted Member
[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?
-
May 24th, 2013, 04:30 PM
#2
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!
-
May 24th, 2013, 04:47 PM
#3
Thread Starter
Addicted Member
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
-
May 24th, 2013, 08:27 PM
#4
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!
-
May 24th, 2013, 08:31 PM
#5
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...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 24th, 2013, 10:13 PM
#6
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
-
May 25th, 2013, 11:12 AM
#7
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!
-
May 26th, 2013, 07:48 PM
#8
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|