|
-
Apr 25th, 2010, 03:32 AM
#1
Thread Starter
Addicted Member
Hiding and showing tabs
Hey,
I'm trying to search through all tabs to find a specific text.
if the text is found, the tab will be hidden, or shown.
I tried this to hide:
btnHide
Code:
Dim txt As Object
Dim tabp As TabPage
For Each tabp In TabControl1.TabPages
For Each txt In tabp.Controls
If TypeOf txt Is Label Then
If txt.text = "Kapaza" Then
tabp.Hide()
End If
End If
Next
Next
and this to show:
btnShow
Code:
Dim txt As Object
Dim tabp As TabPage
For Each tabp In TabControl1.TabPages
For Each txt In tabp.Controls
If TypeOf txt Is Label Then
If txt.text = "Kapaza" Then
tabp.Show()
End If
End If
Next
Next
but it only hides the controls on the currently selected tab.
It should hide the tab (when pressing btnHide)
(so remove it from the list of tabs)
But it should be shown again at the press of btnShow
(added again to the list, at the end)
-
Apr 25th, 2010, 03:42 AM
#2
Hyperactive Member
Re: Hiding and showing tabs
I tried once to hide a tab in similar way and after trying and trying it did not work...
What I did in the end was to disable the tab - maybe this idea will push you in the right direction. Instead hiding tabs you don't want, disable them - thats the best I was able to do it and most importantly I was satisfied with that solution...
-
Apr 25th, 2010, 03:47 AM
#3
Thread Starter
Addicted Member
Re: Hiding and showing tabs
That probably wont do, as some tabs need to be filtered out.
Is it possible to move a tab to a different tabcontrol and then moev it back?
-
Apr 25th, 2010, 03:53 AM
#4
Frenzied Member
Re: Hiding and showing tabs
if you dont need the tabpage back then you can dispose it
-
Apr 25th, 2010, 03:54 AM
#5
Thread Starter
Addicted Member
Re: Hiding and showing tabs
Yeah, but I need it back.
-
Apr 25th, 2010, 04:01 AM
#6
Frenzied Member
Re: Hiding and showing tabs
ok try this. it requires a little bit of tweaking, but gives you the basic idea.
vb Code:
Dim tp As TabPage Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click tp = Me.TabControl1.TabPages(2) Me.TabControl1.TabPages.Remove(tp) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.TabControl1.TabPages.Add(tp) End Sub
-
Apr 25th, 2010, 04:12 AM
#7
Thread Starter
Addicted Member
Re: Hiding and showing tabs
I figured it out, I'll psot the code soon.
I'm adding comment atm.
Code:
'show tab
Dim txt As Object
Dim tabp As TabPage
'loop through all tabs in
For Each tabp In TabControl2.TabPages
'loop through all objects in the tab
For Each txt In tabp.Controls
'check if it's a label
If TypeOf txt Is Label Then
'if it's a label, see what the text is
If txt.text = "Autozone" Then
'if it's that text, move it to the first tabcontrol
'it'll be removed from the second tab
TabControl1.TabPages.Add(tabp)
End If
End If
Next
Next
Code:
'hide tab
Dim txt As Object
Dim tabp As TabPage
'loop through first control
For Each tabp In TabControl1.TabPages
For Each txt In tabp.Controls
If TypeOf txt Is Label Then
If txt.text = "Autozone" Then
'add to second
TabControl2.TabPages.Add(tabp)
End If
End If
Next
Next
This code works fine
-
Apr 25th, 2010, 04:20 AM
#8
Frenzied Member
Re: Hiding and showing tabs
vb Code:
If TypeOf txt Is Label Then 'if it's a label, see what the text is If txt.text = "Autozone" Then
you can combine these two lines using AND
-
Apr 25th, 2010, 04:28 AM
#9
Re: Hiding and showing tabs
You can just remove the TabPage from the TabPages collection. If you still need it later, just store it in a (probably global) variable of type TabPage, or if you need multiple pages, of type List(Of TabPage). Then you can simply Add it back in at a later time. That will add it to the end though, if you need it at a specific place I think the only way you can do that is by taking out all tabpages, putting them in some collection (List(Of TabPage)), using Insert on that collection (which is not available for a TabPageCollection), and then putting them back into the TabControl.
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
|