Sheritlw
asked on
Restore hidden tabpage to original position when stored in dictionary
I am using the code below to hide and show tabs. The tab names are stored in a dictionary
The code I am currently using works great if you just need to append the shown tab to the end of the tabcontrol, but not when you need to show it in it's original location before hidden.
I tried using insert, but it does not restore the correct tabpage. Each tab pages controls are numbered according to the tabs index, so if a using wants to show a tab, they select the tab they want to display and I need to display that tab.
It works if I just add the tab, but if I insert the tab, I get a different tab.
Basically I need to append the tab to the 2nd to last position in the tabControl.
i.e. position = tabcontrol1.tabcount - 2
I hope this is clear.
Anyone have any ideas?
Thanks
Tab 0 = controlname & 0
so the name would be controlname0
Tab 1 = controlname & 1
so the name would be controlname1
etc.
The code I am currently using works great if you just need to append the shown tab to the end of the tabcontrol, but not when you need to show it in it's original location before hidden.
I tried using insert, but it does not restore the correct tabpage. Each tab pages controls are numbered according to the tabs index, so if a using wants to show a tab, they select the tab they want to display and I need to display that tab.
It works if I just add the tab, but if I insert the tab, I get a different tab.
Basically I need to append the tab to the 2nd to last position in the tabControl.
i.e. position = tabcontrol1.tabcount - 2
I hope this is clear.
Anyone have any ideas?
Thanks
Tab 0 = controlname & 0
so the name would be controlname0
Tab 1 = controlname & 1
so the name would be controlname1
etc.
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
tab.index is not an option for a tabpage.
thanks
thanks
'Replace your code to this...
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
Then add this code.
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(
End Sub
Then add this code.
Private Function GetIndex(Byval Tabname as string) as integer
For ctr As Integer = 0 To TabControl1.TabPages.Count - 1
If TabControl1.TabPages(ctr).Name = Name Then
Return ctr
End If
Next
Return -1
End Function
oopps... typing error...
Add this code instead
Add this code instead
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
ASKER
That looks good, how would I show the tab now?
Thanks
Thanks
Just use this code....
Private Sub RetrieveTab(name As String)
Dim tab As TabPage = tabs(name)
tabs.Remove(tab)
TabRacing.TabPages.Insert( tab.tag, tab)
End Sub
Below is the complete and working code...
Private Sub RetrieveTab(name As String)
Dim tab As TabPage = tabs(name)
tabs.Remove(tab)
TabRacing.TabPages.Insert(
End Sub
Below is the complete and working code...
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
ASKER
It still appends the tab to the end of the tabcontrol.
thanks
thanks
ASKER
If it would be easier. Just as long as the tab is shown before the last tab.
When I hide the tabs I use the following...
For p As Integer = ft.TabRacing.TabCount - 2 To iMaxTabs Step -1
ft.HideTab(ft.TabRacing.Ta bPages(p). Name)
Next
When I hide the tabs I use the following...
For p As Integer = ft.TabRacing.TabCount - 2 To iMaxTabs Step -1
ft.HideTab(ft.TabRacing.Ta
Next
What does this code do? Can you explain?
For p As Integer = ft.TabRacing.TabCount - 2 To iMaxTabs Step -1
ft.HideTab(ft.TabRacing.Ta bPages(p). Name)
Next
For p As Integer = ft.TabRacing.TabCount - 2 To iMaxTabs Step -1
ft.HideTab(ft.TabRacing.Ta
Next
I have here an example.... Please check
https://filedb.experts-exchange.com/incoming/ee-stuff/7645-RestoreHiddenTab.zip
https://filedb.experts-exchange.com/incoming/ee-stuff/7645-RestoreHiddenTab.zip
Small flaw in your plan Sheritlw, if you try to store the index of the tabpage and do some adding and removing how will an index of 5 work if they now have only 2 pages showing?
ASKER
Yes, I see the flaw. Basically I need to move the added tab over one position
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If your adding controls based on the index, this is the wrong approach. You could try to store the number in the tag property. This way as you add/remove controls it will not change the tag and it will load the right controls for you. Is this more like what you are doing?
ASKER
Well it looks like I got it working.
A page with grids already filled in would appear, so I basically had to reset everything so it would then be a blank and new tab, ready for data entry.
The show is as follows...
Private Function ShowTab(ByVal sName As String) As TabPage
Dim tab As TabPage = tabs(sName)
TabRacing.TabPages.Insert( Me.TabRaci ng.TabCoun t - 1, tab)
tabs.Remove(sName)
Return tab
End Function
Since I used info from both reply's, I will split the points.
Thanks for your help,
A page with grids already filled in would appear, so I basically had to reset everything so it would then be a blank and new tab, ready for data entry.
The show is as follows...
Private Function ShowTab(ByVal sName As String) As TabPage
Dim tab As TabPage = tabs(sName)
TabRacing.TabPages.Insert(
tabs.Remove(sName)
Return tab
End Function
Since I used info from both reply's, I will split the points.
Thanks for your help,
Open in new window