Tabpages ordering

  • Thread starter Thread starter VJ
  • Start date Start date
V

VJ

Is there a way to Order Tabpages..

I tried to Use a Class that implements the IComparer and a Compare method as
suggested in the MSDN article. "ArrayList.Sort()" and then use the instance
of this class to sort like..

tbControl.TabPages.Sort(lstSorter)

There seems to be no effect..... I have tried debugging, the sorting seems
to happen, but Tabpages don't get rearranged. I even tried Referesh(),
Invalidate() methods.. after sort, nothing seems to work...

VJ
 
You have to remove the tabpages from tabcontrol and add them again in the
order you want them.

Private _tabs(3) As TabPage ' variable to hold tabpages

Private Sub SortTabPages(ByVal currentTab As TabPage)


' To reorder the tabs, clear the collection and add them again

TabControl1.TabPages.Clear()
For Each tab As TabPage In _tabs
If Not tab Is Nothing Then
TabControl1.TabPages.Add(tab)
End If
Next

TabControl1.SelectedTab = currentTab


End Sub

HTH,
Greg
 
* "VJ said:
Is there a way to Order Tabpages..

I tried to Use a Class that implements the IComparer and a Compare method as
suggested in the MSDN article. "ArrayList.Sort()" and then use the instance
of this class to sort like..

Remove the 'TabPage' objects from the 'TabPages' collection and add them
in the desired order.
 
No time for a proper answer, Im off to work.
Rather than remove and replace tabpages, which causes flicker, just swap
pages as you sort. Here's a quick implementation of swap without sort.

\\\
Public Sub SwapTabPages(ByVal tp1 As TabPage, ByVal tp2 As TabPage)
Dim Index1 As Integer = TabPages.IndexOf(tp1)
Dim Index2 As Integer = TabPages.IndexOf(tp2)
TabPages(Index1) = tp2
TabPages(Index2) = tp1
End Sub
///

If you're on about design time order then you'll find the answer here:
http://dotnetrix.co.uk/tabcontrols.html --> Tabpage order has changed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top