Insert a Hidden Tab in TabControl

I am using the code below to hide and show tabs.
It was working great until I had to add another tab to the end of the tab list.
So when I add the tab, it goes to the end of the list and I need it to inserted into the 2nd to last tab position.
I tried insert, but the controls on the tab no longer line up with the numbering system I use.
All controls on Tabs are the same name with the index of the tab appended.
i.e.  
Tab 0 =  controlname & 0
so the name would be controlname0
Tab 1 =  controlname & 1
so the name would be controlname1

etc.

There are numerous controls/grids on each tab and each is named that way.
How do I position the tab that is being show in the position tabcontrol.selectedindex - 2

Thank you
Dim tabs As New System.Collection.Generic.Dictionary(Of String, TabPage)
 
Private Sub RemoveTab(name As String)
  Dim tab As TabPage = TabRacing.TabPages(name)
 
  tabs.Add(name, tab)
  TabRacing.TabPages.Remove(tab)
End Sub
 
Private Sub RetrieveTab(name As String)
  Dim tab As TabPage = tabs(name)
  tabs.Remove(tab)
  TabRacing.TabPages.Add(tab)
End Sub

Open in new window

SheritlwAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hawkvalley1Commented:
Well the insert index would be tabControl.tabpages.count -2, this would get you the second to last index in the tabpage order.
0
SheritlwAuthor Commented:
Yes, I am aware of that.  Each tabpage has a set of numbered controls.  
When they click to add a tab, they are asked which tab to add. This tab has already been created at design time and was just hidden.  I need to show everything about the selected tab.
0
Hawkvalley1Commented:
I read the question and that looked like what you were asking.
0
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

SheritlwAuthor Commented:
Expert oobayly gave me my original solution.  Is there anyone that may know how to insert a hidden tab before the last tab in a TabControl?
0
JackOfPHCommented:
Here try this code of mine, the code I supplied will restore the tab to its original location.
Private Sub RemoveTab(name As String)
  Dim tab As TabPage = TabRacing.TabPages(name)
 
  tabs.Add(name, tab)
  tab.tag = GetIndex(name)  '<----  This will store the original index location of the tab in the tag property.
  TabRacing.TabPages.Remove(tab)
End Sub
 
 Private Sub RetrieveTab(name As String)
  Dim tab As TabPage = tabs(name)
  tabs.Remove(tab)
  TabRacing.TabPages.Insert(tab.tag, tab)
End Sub
 
Private Function GetIndex(Byval Tabname as string) as integer
 
        For ctr As Integer = 0 To TabControl1.TabPages.Count - 1
            
            If TabControl1.TabPages(ctr).Name = TabName Then
                Return ctr
            End If
 
        Next
 
        Return -1
 
End Function

Open in new window

0
SheritlwAuthor Commented:
Solution

Private Function ShowTab(ByVal sName As String) As TabPage
        Dim tab As TabPage = tabs(sName)

        TabRacing.TabPages.Insert(Me.TabRacing.TabCount - 1, tab)
        tabs.Remove(sName)

        Return tab

    End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.