Changing currently selected tab programatically

7 posts, 1 answers
  1. Jack
    Jack avatar
    25 posts
    Member since:
    Feb 2011

    Posted 24 Feb 2011 Link to this post

    Hello -

    I thought this would be easy enough, and am still sure it must be, but .....

    Can anyone post a snippet of:

    1) How I would change the currently selected tab in a radribbonbar programatically?
    2) Tell me which event gets fired when the selected tab changes?

    My situation is that I have a standard windows tab control nested under the radribbonbar control. When the user changes the selected tab on the radribbonbar, I need to change the selected tab on the standard windows tab control as well.

    Thanks much -
    Jack

  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 25 Feb 2011 Link to this post

    Hello Jack,

    this should answer both your questions. It shows how to select a tab, and also registering an event handler to show when the tab has changed.
    Private Sub RadRibbonForm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddHandler Me.RibbonTab1.PropertyChanged, AddressOf RibbonTab1_PropertyChanged
        Me.RibbonTab1.IsSelected = True
    End Sub
    Private Sub RibbonTab1_PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
        If e.PropertyName = "IsSelected" Then
            MessageBox.Show("RibbonTab1 Selected")
        End If
    End Sub


    Let me know if you have any questions
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 28 Feb 2011 Link to this post

    Hello,

    If you found this helpful, please remember to mark as answer. If you need further assistance, please let me know
    Thanks
    Richard
  5. Jack
    Jack avatar
    25 posts
    Member since:
    Feb 2011

    Posted 28 Feb 2011 Link to this post

    Richard -

    This doesn't seem to work; (maybe I lost something in the VB to C# conversion)

    public Form1() 
          InitializeComponent(); 
          this.radRibbonBar1.PropertyChanged += new PropertyChangedEventHandler(radRibbonBar1_PropertyChanged);  
          this.ribbonTab1.IsSelected = true;
      
    private void radRibbonBar1_PropertyChanged(object sender, EventArgs e) 
                // Never fires 
    }


    However, the following event does fire, which achieves my goal:

     
    private void radRibbonBar1_CommandTabSelected(object sender, Telerik.WinControls.UI.CommandTabEventArgs args)
    {            
        if (args.CommandTab.Text == "foo1")
        {
        }            
    }

     

     

    But I'm left wondering ..

    Did I miss something in the translation, or is the CommandTabSelected event the one I should trap?

    Thanks
    Jack



  6. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 28 Feb 2011 Link to this post

    Hi Jack,

    Yes, the problem in your code was that you were handling the event for the RadRibonBar, not the RibbonTab. The event is for each RibbonTab that you have in your RadRibbonBar, but I'm glad you have another solution which seems also to be fine.
    regards,
    Richard
  7. Jack
    Jack avatar
    25 posts
    Member since:
    Feb 2011

    Posted 28 Feb 2011 Link to this post

    Thanks Richard,

    I went back and tested and your original solution works as well... sorry, havn't had my morning pot of coffee yet.

    Thanks
    Jack
  8. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 28 Feb 2011 Link to this post

    We all need our morning coffee Jack. Glad it helped. Your solution is fine too.
    Thanks
    Richard
Back to Top
UI for WinForms is Visual Studio 2017 Ready