Solved

Retrieve TabPage from ArrayList

Posted on 2009-05-06
3
365 Views
Last Modified: 2012-05-06
I have been looking on the net for a way to hide/show tabpages in a tabcontrol.
I found a topic on adding the tabpages to an arraylist so they can be easily retrieved after being removed.
I have them hiding/removing using

Private aHideTabPages As New ArrayList()
    Public Sub HideTab(ByVal t As Object)
        aHideTabPages.Add(Me.TabRacing.TabPages(t))
        'Remove page from tabcontrol
        TabRacing.TabPages.RemoveAt(t)
    End Sub

But how do I bring back the correct tab?
I looked all over the net trying to find a solution, with no luck, so I tried ---
Private Sub ShowTab(ByVal t As Object)
        TabRacing.TabPages.Add(aHideTabPages.Item(t))
End Sub
This doesn't work.
Please provide an example (no links please) of how I would retrieve the correct tabpage back from the arraylist.
Thanks
0
Comment
Question by:Sheritlw
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
oobayly earned 500 total points
ID: 24319906
First of all, use a Generics as they're type safe.

The question is, how do you know which tab you want to retrieve, are you doing it by name? By index is tricky as the index will change as tabs are removed and added.

Do you need the tabs to be replaced in the tab control in a specific order, or can the be appended to the end of the the tab control?

You're using t as an object in both methods you've given us, can we assume that it's an integer? It would be a good idea specify Option Strict On in your project too.

The following code uses a string (Tab Name) as a key to keep track of the tabs in both the TabControl & the dictionary of removed tabs.
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

0
 

Author Comment

by:Sheritlw
ID: 24321579
The tabpages can just be appended to the end of the tabcontrol.

I am setting up your code now.
Thanks
0
 

Author Closing Comment

by:Sheritlw
ID: 31578581
Great idea.   Thank you .. works great!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now