Solved

Loop through Indexes in Descending Order

Posted on 2009-05-06
4
809 Views
Last Modified: 2012-05-06
I have 5 tabs (indexed at 0). Users select what options they want and then I remove the rest of the tabs from the end of the tabcontrol.  If they want to add a tab back they can do that also.
My problem is, I need to loop through the tabs in order to remove them.
Lets say a user has selected 4 items, 0 based, so I would need to remove 2 tabs.

As I loop through and remove the tabs, the last index is not longer available so I will get an error.
Is there a way to loop through the tabcount in descending order?

For Each i As Object In Me.lstChkSessions.CheckedItems
 
            s = Me.lstChkSessions.GetItemText(i).ToString
            ft.TabRacing.TabPages(c).Text = s
            Dim view As DataRowView = Me.lstChkSessions.CheckedItems(c)
            ft.TabRacing.TabPages(c).Tag = view.Item("SessionTypeID")
            c = c + 1
 
        Next i
 
        For p As Integer = c To ft.TabRacing.TabCount - 1
            ft.HideTab(ft.TabRacing.TabPages(p).Name)
        Next

Open in new window

0
Comment
Question by:Sheritlw
  • 3
4 Comments
 
LVL 15

Accepted Solution

by:
JackOfPH earned 500 total points
ID: 24321700
Try this code...
For p As Integer =  ft.TabRacing.TabCount - 1 to c step -1
            ft.HideTab(ft.TabRacing.TabPages(p).Name)
Next

Open in new window

0
 

Author Closing Comment

by:Sheritlw
ID: 31578834
Works great... Thanks
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24321802
Did it work?
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24321803
Glad I could help...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 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