Check if dynamically added tab exists

6 posts, 0 answers
  1. junk smith
    junk smith avatar
    4 posts
    Member since:
    Aug 2009

    Posted 06 Aug 2009 Link to this post

    I have a radtabstrip in a VB.NET project. examples to add and remove tabs have been noted and used.
    using values from a database, tabs with unique names are created. how do i check whether the tab already exists prior to creating it?

    Cheers


      
  2. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 12 Aug 2009 Link to this post

    Hi junk smith,

    Thank you for writing. You can check if the tab item exists by implementing simple iteration over the Items collection. Or you can use Array.Exists method as well. Please, consider the following code:

    Private Sub Form1_Load(ByVal sender As ObjectByVal e As EventArgs)  
        If Array.Exists(Of RadItem)(Me.radTabStrip1.Items.ToArray(), FindItem) Then 
            'do something...  
        End If 
    End Sub 
     
    Private Shared Function FindItem(ByVal item As RadItem) As Boolean 
        If item.Name.Equals("My_Tab_Name"Then 
            Return True 
        Else 
            Return False 
        End If 
    End Function 

    I hope this helps. Do not hesitate to contact me again if you have other questions.

    Sincerely yours,
    Martin Vasilev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. junk smith
    junk smith avatar
    4 posts
    Member since:
    Aug 2009

    Posted 14 Aug 2009 Link to this post

    Hi

    Thanks for the reply, i came up with a different way;

     For Each ti As TabItem In tabcontrol.Items
                    If ti.Name = TABNAMETOCHECK Then
                        TabExists = True

                    End If

                Next
  5. Nick
    Admin
    Nick avatar
    767 posts

    Posted 14 Aug 2009 Link to this post

    Hello junk smith,

    I am glad that you found a better approach for your application. Thank you for sharing it with the community.

    Best wishes,
    Nick
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. junk smith
    junk smith avatar
    4 posts
    Member since:
    Aug 2009

    Posted 14 Aug 2009 Link to this post

    Only different, not necessarily better

    Cheers


  7. Erwin
    Erwin avatar
    10 posts
    Member since:
    Oct 2009

    Posted 22 Oct 2009 Link to this post

    Even better:

    Private Sub Form1_Load(ByVal sender As ObjectByVal e As EventArgs)   
        If Not Me.radTabStrip1.Items.SingleOrDefault(Function(s) s.Name.Equals("My_Tab_Name")) Is Nothing Then  
            'do something...   
        End If  
    End Sub  

    :-)

    (Works starting from VB9).
Back to Top
UI for WinForms is Visual Studio 2017 Ready