Solved

Retrieve TabPage from ArrayList

Posted on 2009-05-06
3
374 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

772 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