Results 1 to 9 of 9

Thread: Tabpage - Add or insert tabpage with order determined

Threaded View

  1. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Tabpage - Add or insert tabpage with order determined

    Quote Originally Posted by dday9 View Post
    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:
    1. 'Get the first TabPage with a greater Tag value than the one being inserted.
    2. Dim followingTab = myTabControl.TabPages.Cast(Of TabPage)().FirstOrDefault(Function(tp) CInt(tp.Tag) > CInt(tabToInsert.Tag))
    3.  
    4. If followingTab Is Nothing Then
    5.     'There is no following tab so add this one to the end.
    6.     myTabControl.TabPages.Add(tabToInsert)
    7. Else
    8.     'Insert this tab before the following one.
    9.     myTabControl.TabPages.Insert(myTabControl.TabPages.IndexOf(followingTab), tabToInsert)
    10. End If
    Last edited by jmcilhinney; Jun 3rd, 2014 at 06:05 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width