Last Selected Tab?

6 posts, 1 answers
  1. Mike
    Mike avatar
    76 posts
    Member since:
    Nov 2004

    Posted 07 Jan 2009 Link to this post

    Hi Guys,

    I have a bit of an issue.  When my user switches tabs I run a lengthly process, but this process only needs to be run coming from one specific tab.  So...  How do I identify what was the last selected tab?

    Example:
    ----------------------------
    Tab 1    Tab2    Tab3

    On click of Tab2 from Tab1 I run process XYZ.  On click of Tab2 from Tab3 I want to bypass process XYZ.  When the user clicks on Tab2 how do I know the previous selected tab?

    Many thanks,
    ~Mike

  2. Answer
    Deyan
    Admin
    Deyan avatar
    2037 posts

    Posted 07 Jan 2009 Link to this post

    Hello Mike,

    Thanks for writing.

    I have prepared a sample project which demonstrates a possible way to implement the desired behavior. The idea is to save the last active tab in a variable and check this variable each time a new tab is selected. If the variable contains the tab in question, then you perform your action.

    Note that in the constructor of my form I am initializing the lastSelectedTab variable with the initially selected TabItem in order not to brake the approach.

    I hope this will help you.

    Do not hesitate to write back if you need further assistance.

    Kind regards,
    Deyan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Mike
    Mike avatar
    76 posts
    Member since:
    Nov 2004

    Posted 08 Jan 2009 Link to this post

    Sure, that is one way to do it, but I hoping you had something built-in I was missing.

    Might be a nice little feature to add - I'm sure it wouldn't be all that hard.  :)

    Thanks for taking the time to write a sample.

    ~Mike
  5. Deyan
    Admin
    Deyan avatar
    2037 posts

    Posted 09 Jan 2009 Link to this post

    Hi Mike,

    In fact, I have researched your question a bit more and found another, easier way to get the last selected tab after a new one has been selected.

    You can use the TabSelecting event which provides you with a reference to the tab that is going to be selected. At this point, the RadTabStrip.SelectedTab points to the currently selected tab in the control and TabCancelEventArgs.TabItem points to the tab that is going to be selected. Consider the code snippet below:

    private void On_TabSelecting(object sender, TabCancelEventArgs args) 
        //this.radTabStrip1.SelectedTab contains the currently selected tab 
        TabItem item = this.radTabStrip1.SelectedTab as TabItem; 
        if (item != null && item.Text == "<NameOfTab>"
        { 
            //Trigger lenghty action 
        } 



    Sincerely yours,
    Deyan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Andrea Licitra
    Andrea Licitra avatar
    1 posts
    Member since:
    Nov 2009

    Posted 04 Nov 2009 Link to this post

    Hi!

    I'm Italian and I'm new here, so please my bad english! :)
    I tried this code posted by Telerik Admin, converted to VB, because I develop applications in Visual Basic 2005 .NET:
    Private Sub On_TabSelecting(sender As Object, args As TabCancelEventArgs) 
        'this.radTabStrip1.SelectedTab contains the currently selected tab  
        Dim item As TabItem = TryCast(Me.radTabStrip1.SelectedTab, TabItem) 
                'Trigger lenghty action  
        If item <> Nothing AndAlso item.Text = "<NameOfTab>" Then 
        End If 
    End Sub 

    I'd like to implement this, when the users click the RadElement placed on each tab, that is a Close Button (made through Telerik Demos).
    In fact, if I normally close one tab and use "Me.RadTabStrip1.SelectLastVisibleItem()", it selects the first tab...

    Any ideas to fix this?

    Thanks in advance, Andrea.
  7. Deyan
    Admin
    Deyan avatar
    2037 posts

    Posted 06 Nov 2009 Link to this post

    Hello Andrea,

    I am not quite sure that I understand the behavior that you would like to implement? Could you please share some more details so that I can provide further help? Thanks for your time.

    Sincerely yours,
    Deyan
    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.
Back to Top
UI for WinForms is Visual Studio 2017 Ready