locked
Problem Adding and Removing Tabs with the Windows Forms TabControl RRS feed

  • Question

  • I have 13 tabs in my Main Form. All the tabs have many fields where user enters the data. In the first tab, there are different selections. Each selection opens different other tabs. For ex. Selection 1 opens Tab # 1) 2) 8) 11) and 12), and all the other tabs are supposed to become invisible.

    I tried using the following code to accomplish the above,

            Me.SSTab1.TabPages.Add(SSTab1_TabPage1)
                     Me.SSTab1.TabPages.Add(SSTab1_TabPage2)
                     Me.SSTab1.TabPages.Add(SSTab1_TabPage8)
                    Me.SSTab1.TabPages.Add(SSTab1_TabPage10)
                   Me.SSTab1.TabPages.Add(SSTab1_TabPage11)

                 Me.SSTab1.TabPages.Remove(SSTab1_TabPage3)
                  Me.SSTab1.TabPages.Remove(SSTab1_TabPage9)
                  Me.SSTab1.TabPages.Remove(SSTab1_TabPage6)
                 Me.SSTab1.TabPages.Remove(SSTab1_TabPage5)
                  Me.SSTab1.TabPages.Remove(SSTab1_TabPage4)
                  Me.SSTab1.TabPages.Remove(SSTab1_TabPage7)
                 Me.SSTab1.TabPages.Remove(SSTab1_TabPage12)
                 Me.SSTab1.TabPages.Remove(SSTab1_TabPage13)

    but what happened is that all tabs that were added by code, came in empty. Absolutely containing no fields or any data.

    I need working code that will make visible the tabs, bringing in all the fields and data, and make the other tabs invisible, without losing any information.

    You can be sure that I searched for sample code and solutions and I have not found any yet.

    I tried making the tabs visible, but "invisible" does not work, so I tried using the code "Remove" but it didn't either work, because if I used Visible and Remove, for Tab 1,2, 8, 10, 11, then Tabs 1 and 2 displayed properly, but 8, 10, 11 were empty, since the tabs before these 3 were "Removed".

    Please reply with working code. Thank You.

    Tuesday, November 3, 2020 1:07 AM

All replies

  • Hi

    First of all - this forum s NOT a software writing service and demands for working code are not acceptable.

    The reason your code is not working as you expect is that you are removing TabPages and losing all the controls and data on them - use .Visible = True or .False to show/hide a TabPage.Also, when adding a TabPage, that is OK, but you are only adding a blank TabPage by doing that.

    WRONG: .visible property not the solution.


    Regards Les, Livingston, Scotland



    • Edited by leshay Thursday, November 12, 2020 1:58 PM
    Tuesday, November 3, 2020 1:31 AM
  • The best path is different than what you have now and the alternate path I've not seen in VB.NET, only in C# after a five minutes search.

    Look for VB.NET create wizard.

    Here is what I'm talking about in C# on this page. Although most wizards work from 1 to finish that does not mean they need too.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    My GitHub code samples
    GitHub page

    Tuesday, November 3, 2020 2:01 AM
  • Thanks 

    I tried the following:

        Me.SSTab1.TabPages(0).Visible = True
                Me.SSTab1.TabPages(0).Enabled = True
                Me.SSTab1.TabPages(1).Visible = True
                Me.SSTab1.TabPages(1).Enabled = True
                Me.SSTab1.TabPages(2).Visible = True
                Me.SSTab1.TabPages(2).Enabled = True
                Me.SSTab1.TabPages(8).Visible = True
                Me.SSTab1.TabPages(8).Enabled = True
                Me.SSTab1.TabPages(10).Visible = True
                Me.SSTab1.TabPages(10).Enabled = True
                Me.SSTab1.TabPages(11).Visible = True
                Me.SSTab1.TabPages(11).Enabled = True
                Me.SSTab1.TabPages(3).Visible = False
                Me.SSTab1.TabPages(3).Enabled = False
                Me.SSTab1.TabPages(4).Enabled = False
                Me.SSTab1.TabPages(4).Visible = False
                Me.SSTab1.TabPages(5).Enabled = False
                Me.SSTab1.TabPages(5).Visible = False
                Me.SSTab1.TabPages(6).Enabled = False
                Me.SSTab1.TabPages(6).Visible = False
                Me.SSTab1.TabPages(7).Enabled = False
                Me.SSTab1.TabPages(7).Visible = False
                Me.SSTab1.TabPages(9).Enabled = False
                Me.SSTab1.TabPages(9).Visible = False
                Me.SSTab1.TabPages(12).Enabled = False
                Me.SSTab1.TabPages(12).Visible = False

    The code "Visible = False" is not working and "Enabled=False" is working, which means that all the tabs remain but are displaying greyed out. Which code is the proper code to make the tabs be totally invisible.

    I'm looking forward to your answer.


    Tuesday, November 3, 2020 3:16 PM
  • Perhaps the following code sample will be of assistance which is the frontend and the following is a class project with the functionality to hide/show tab pages.

    Now it's not an answer but a path to hide/show tab pages, one at a time or all. Also has other functionality to explore in TabControlHelper.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    My GitHub code samples
    GitHub page

    Tuesday, November 3, 2020 5:58 PM
  • Hi MosheS Singer,

    How's the question going?

    I make a simple test on my side and the 'TabPage4' in my test didn't lose any information.

    Here's the code of my test.

        Private Sub HidePage24Btn_Click(sender As Object, e As EventArgs) Handles HidePage24Btn.Click
            TabControl1.TabPages.Remove(TabPage2)
            TabControl1.TabPages.Remove(TabPage4)
        End Sub
    
        Private Sub ShowPage4Btn_Click(sender As Object, e As EventArgs) Handles ShowPage4Btn.Click
            If Not TabControl1.TabPages.Contains(TabPage4) Then
                TabControl1.TabPages.Add(TabPage4)
            End If
        End Sub

    >>what happened is that all tabs that were added by code, came in empty. Absolutely containing no fields or any data.

    Could you provide more details or more related code about this? It will help us make a test.

    We are waiting for your update.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 12, 2020 8:18 AM