
Originally Posted by
dday9
The way that I would do it is to set the Tag property of the tab page to whatever order it should be in. Then whenever you add a page, use the Add method, then iterate through each tab to check which order they should be in, and finally set the proper order then.
I like the idea of using the Tag but don't Add and then re-order. Determine the correct order first and then use Insert. E.g.
vb.net Code:
'Get the first TabPage with a greater Tag value than the one being inserted.
Dim followingTab = myTabControl.TabPages.Cast(Of TabPage)().FirstOrDefault(Function(tp) CInt(tp.Tag) > CInt(tabToInsert.Tag))
If followingTab Is Nothing Then
'There is no following tab so add this one to the end.
myTabControl.TabPages.Add(tabToInsert)
Else
'Insert this tab before the following one.
myTabControl.TabPages.Insert(myTabControl.TabPages.IndexOf(followingTab), tabToInsert)
End If