Tab order

4 posts, 1 answers
  1. IT Development
    IT Development avatar
    25 posts
    Member since:
    Mar 2009

    Posted 28 Sep 2009 Link to this post

    Hello,

     

    Having some trouble with the tabcontrol.

     

    I want to remember tab visibility and order.  When the user closes the form I save the visible tabitems in a List<string> .

     

    When the form gets loaded I would like to restore the tabs.

    I can control the visibility of the tabs but I can’t find a way to restore the order.

     

    Anybody got a suggestion?

     

    Kind regards,

     

    Tim van Rooijen

  2. Answer
    Robert
    Robert avatar
    82 posts
    Member since:
    Jun 2009

    Posted 30 Sep 2009 Link to this post

    Hey Tim,

    The tab order of a RadTabStrip is determined by the order of the TabItems in the RadTabStrip.Items collection. In the following code, I save the tab order to a list then restore the tab order in radTabStrip1 based on that list.

        public partial class Form1 : Form 
        { 
            List<string> tabOrder = new List<string>(); 
     
            public Form1() 
            { 
                InitializeComponent(); 
            } 
     
            private void btnChangeTabOrder_Click(object sender, EventArgs e) 
            { 
                List<RadItem> tabItems = new List<RadItem>((IEnumerable<RadItem>)radTabStrip1.Items); 
     
                radTabStrip1.Items.Clear(); 
     
                // Restore the tabs in order in the RadTabStrip 
                foreach (string tabName in tabOrder) 
                { 
                    foreach (TabItem item in tabItems) 
                    { 
                        if (item.Name == tabName) 
                            radTabStrip1.Items.Add(item); 
                    } 
                } 
            } 
     
            private void btnSaveTabOrder_Click(object sender, EventArgs e) 
            { 
                // Save order of tabs 
                tabOrder.Clear(); 
     
                foreach (TabItem item in radTabStrip1.Items) 
                    tabOrder.Add(item.Name); 
            } 
        } 

    I hope this helps.

    - Robert
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 01 Oct 2009 Link to this post

    Hi Robert,

    Thank you for sharing your approach with us. I thing there is one more convenient solution -- using Queue<>. In that way you can very easily save and reproduce the TabItems and their order:

    Queue<TabItem> itemsQueue = new Queue<TabItem>(); 
     
    private void saveButton_Click(object sender, EventArgs e) 
        this.itemsQueue.Clear(); 
     
        for (int i = 0; i < this.radTabStrip1.Items.Count; i++) 
        { 
            this.itemsQueue.Enqueue((TabItem)this.radTabStrip1.Items[i]); 
        } 
     
        this.radTabStrip1.Items.Clear(); 
     
     
    private void restoreButton_Click(object sender, EventArgs e) 
        while (this.itemsQueue.Count > 0) 
        { 
            this.radTabStrip1.Items.Add(this.itemsQueue.Dequeue()); 
        } 

    Greetings,
    Martin Vasilev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. IT Development
    IT Development avatar
    25 posts
    Member since:
    Mar 2009

    Posted 01 Oct 2009 Link to this post

    Hello,

    Thanks for the reply's.
    It worked!. I choice for the first approach because i wanted to save the order in a string.

    Greetings

    Tim
Back to Top