Selecting Tabs via code

18 posts, 0 answers
  1. dennis_dieckmann
    dennis_dieckmann avatar
    3 posts
    Member since:
    May 2007

    Posted 06 May 2007 Link to this post

    Hi,

    mabe I'm to dumb, but I haven't figured out how I can select a tab with code.

    In the Tabcontrol object from VS05 it's working like this: TabControl1.SelectTab(TabPage2)

    How can I realize this with the Ribbonbar?

    Thanks for your help.

    Dennis
  2. surfer
    surfer avatar
    585 posts
    Member since:
    Jul 2003

    Posted 06 May 2007 Link to this post

    You can use the TabStripElement.SelectedTab property of the RibbonBarElement, for example using the code below you can select the second tab (collection is zero based)

    e.g.

    // C#
    radRibbonBar1.RibbonBarElement.TabStripElement.SelectedTab = radRibbonBar1.RibbonBarElement.TabStripElement.Items[1];

    ' VB.NET
    radRibbonBar1.RibbonBarElement.TabStripElement.SelectedTab = radRibbonBar1.RibbonBarElement.TabStripElement.Items(1)
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 07 May 2007 Link to this post

    Hello Matt Stewart,

    Indeed this works fine but it would be a good idea to check whether the index of the tab is  not out of range of the items collection boundaries.

    e.g.
    int index = 1; 
    if (( radRibbonBar1.RibbonBarElement.TabStripElement.Items.Count < index ) &&  
    (index >=0 )) 
    radRibbonBar1.RibbonBarElement.TabStripElement.SelectedTab = radRibbonBar1.RibbonBarElement.TabStripElement.Items[1]; 



    Regards,
    Ray
    the telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. surfer
    surfer avatar
    585 posts
    Member since:
    Jul 2003

    Posted 07 May 2007 Link to this post

    Sure. This was just to serve the example. Bounds checking is always a good idea. And in your code the check should be reverse:

    e.g.

    instead of
    radRibbonBar1.RibbonBarElement.TabStripElement.Items.Count < index

    this one
    index < radRibbonBar1.RibbonBarElement.TabStripElement.Items.Count
  6. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 07 May 2007 Link to this post

    Hello Matt Stewart,
    I confirm that the index should be smaller than the count of the items in the collection.
    Thank you for the correction.

    Best wishes,
    Ray
    the telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  7. dennis_dieckmann
    dennis_dieckmann avatar
    3 posts
    Member since:
    May 2007

    Posted 07 May 2007 Link to this post

    Hi,

    thank you. This is working fine...

    By the way:
    There is a graphical bug when I do this!

    When you click the tab on the ribbonbar, than everything is ok.
    But if you select a tab with this code, than you have a line under the tab.

    Please have a look on this picture:
    http://dennisdieckmann.de.funpic.de/ribbonbar.png

    I'm using Q4 2006 release.
  8. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 07 May 2007 Link to this post

    Hi dennis_dieckmann,

    We will investigate the problem which you have reported.
    I suggest that you download the  Q1 release of RadControls for WinForms because the line below the TabStrip could have been a bug which is already fixed.
    Thank you for the valuable feedback.


    All the best,
    Ray
    the telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  9. Kevin
    Kevin avatar
    549 posts
    Member since:
    Nov 2006

    Posted 07 May 2007 Link to this post

    Maybe you can try suspending the Form Layout until the changes are made? This is similar to what telerik serialization code does in the Form.Designer.cs files, so it may work around the redrawing issue:

                this.SuspendLayout(); 
                radRibbonBar1.RibbonBarElement.TabStripElement.SelectedTab = radRibbonBar1.RibbonBarElement.TabStripElement.Items[1]; 
                this.ResumeLayout(false); 

  10. dennis_dieckmann
    dennis_dieckmann avatar
    3 posts
    Member since:
    May 2007

    Posted 07 May 2007 Link to this post

    Isn't working in my Project.

    Whatever.. this line isn't that much important to me.
  11. lprada
    lprada avatar
    15 posts
    Member since:
    Apr 2007

    Posted 07 May 2007 Link to this post

    It will be great if you cant select the tab by name or Key. Because if you canhe orders the code is broke.

    Thanks
  12. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 08 May 2007 Link to this post

    Hi Leonardo Prada,

    We agree with you that it would be a nice feature to select a tab by name and we will add it to our To Do list for the scheduled SP2 release.
    If you have any other interesting ideas about adding new features and functionality to our controls please do not hesitate to share them with us.

    Best wishes,
    Ray
    the telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  13. DukeVideo
    DukeVideo avatar
    48 posts
    Member since:
    Jun 2006

    Posted 14 Jun 2007 Link to this post

    What if the tab is in a contextual group?

    I can display the contextual tab group, but how do I auto-select it?

    1if (sender is ProdMasterTab) 
    2            { 
    3 
    4                // hide all tab groups 
    5                foreach (ContextualTabGroup contextualTabGroup in RadRibbonBar.ContextualTabGroups) 
    6                { 
    7                    contextualTabGroup.Visibility=ElementVisibility.Collapsed; 
    8                } 
    9 
    10                foreach (ContextualTabGroup contextualTabGroup in RadRibbonBar.ContextualTabGroups) 
    11                { 
    12                    if ((string)contextualTabGroup.Tag=="ProdMaster"
    13                    { 
    14                        contextualTabGroup.Visibility=ElementVisibility.Visible; 
    15 
    16                         
    17                             
    18                            //TabStripElement.SelectedTab =                this.radRibbonBar1.RibbonBarElement.TabStripElement.Items[0]; 
    19 
    20                        //contextualTabGroup. 
    21                        //RadRibbonBar.SelectedCommandTab=contextualTabGroup.TabItems[0];// =contextualTabGroup.TabItems[0]; 
    22                    } 
    23                } 
    24            } 

  14. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 14 Jun 2007 Link to this post

    Hi Dennis,

    If I understand you correctly, you want to "activate" the contextual group as if it was clicked. The contextual groups in RadRibbonBar do not support this functionality. However when a contextual tab group is clicked the first tab in it will get selected.

    Hope that helps.
     

    Best wishes,
    Jordan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  15. DukeVideo
    DukeVideo avatar
    48 posts
    Member since:
    Jun 2006

    Posted 15 Jun 2007 Link to this post

    Why do they not support that functionality? Seems obvious to me.

    It also happens in Office 2007, so if you were mimicking the Office UI, then why not mimick this feature?
  16. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 15 Jun 2007 Link to this post

    Hello Dennis,

    The RadRibbonBar was designed as per the early drafts of the Office 2007 UI guidelines from Microsoft - this is reason why this difference exists. We are considering some improvements in RadRibbonBar, including the one discussed here, but we cannot give you a specific timeframe at the moment.

    As for the auto activate feature of contextual tab groups - thank you for pointing this out. We have added it in our TODO list for the Q2 2007 release.
     

    Greetings,
    Jordan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  17. DukeVideo
    DukeVideo avatar
    48 posts
    Member since:
    Jun 2006

    Posted 30 Oct 2007 Link to this post

    Hi,

    Has this auto activate of Contextual Groups been added yet? I'm keen to use it to help my users out with their/my usability issues.
  18. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 31 Oct 2007 Link to this post

    Hello DukeVideo,

    Unfortunately, this feature was dropped from the 2007 Q2 release because of some other high priority tasks.
    This feature is still on our TODO list and will be implemented as soon as possible, but we cannot give a specific timeframe at the moment.

    Contact us again if you have additional questions.

    Greetings,
    Jordan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  19. KMBah
    KMBah avatar
    16 posts
    Member since:
    Jun 2007

    Posted 25 Feb 2008 Link to this post

    For those that wanted to select tabs by name (like I needed to), here is some code. It's simple, but it works.

    foreach (RadItem ri in radRibbonBar1.RibbonBarElement.TabStripElement.Items)  
    {  
        if (ri.Text == "TabTextValue")  
        {  
            radRibbonBar1.RibbonBarElement.TabStripElement.SelectedTab = ri;  
            break;  
        }  
Back to Top
UI for WinForms is Visual Studio 2017 Ready