Results 1 to 9 of 9

Thread: Hiding and showing tabs

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    203

    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)

  2. #2
    Hyperactive Member Zeljko's Avatar
    Join Date
    Oct 2006
    Location
    Internet
    Posts
    441

    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...
    1. If this post helped you, please Rate it = That's You, saying Thanks, to Me ...Left side of this post: [Rate this post]
    2. Mark this Thread Resolved if your question has been answered That's You, saying Thanks, to Group ...Menu on top of your original Post: [Thread Tools]>[Mark Thread Resolved]
    3.
    Check my site: www.er-ef.netCheck my snippets: Get installed .NET versionsRegex extractingJoin hierarchically nested Datatables in one flattened Datatable


  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    203

    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?

  4. #4
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    Re: Hiding and showing tabs

    if you dont need the tabpage back then you can dispose it

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    203

    Re: Hiding and showing tabs

    Yeah, but I need it back.

  6. #6
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    Re: Hiding and showing tabs

    ok try this. it requires a little bit of tweaking, but gives you the basic idea.
    vb Code:
    1. Dim tp As TabPage
    2.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    3.         tp = Me.TabControl1.TabPages(2)
    4.         Me.TabControl1.TabPages.Remove(tp)
    5.     End Sub
    6.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    7.         Me.TabControl1.TabPages.Add(tp)
    8.     End Sub

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    203

    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

  8. #8
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    Re: Hiding and showing tabs

    vb Code:
    1. If TypeOf txt Is Label Then
    2.                     'if it's a label, see what the text is
    3.                     If txt.text = "Autozone" Then

    you can combine these two lines using AND

  9. #9
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    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
  •  



Click Here to Expand Forum to Full Width