Dynamically add controls to RadTabstrip

6 posts, 0 answers
  1. bobebs
    bobebs avatar
    7 posts
    Member since:
    May 2007

    Posted 04 May 2007 Link to this post

    I am new to your controls, in VB.Net I am trying to dynamicaly build a form.  I have added the RadTabstrip to my .Net form and I can successfully add tabs in via code.  My problem is I want to add controls to the tab via code also(RadTetxbox, RadListbox) however it is not adding the control to the correct tab.  Below is the code:

    Private Sub Add_Text(ByVal sorder As String, ByVal itab As Integer)

    Dim txt As New RadTextBox

    txt.Name = "Text_" & sorder

    txt.Multiline = True

    txt.ScrollBars = ScrollBars.Both

    Me.RadTabStrip1.SelectedTab = Me.RadTabStrip1.Items(itab)

    Me.TabItem1.ContentPanel.Controls.Add(txt)

    itab is the tab I want to add the control to, it always adds the control to my first tab on the RadTabStrip control.

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

    Posted 04 May 2007 Link to this post

    I see that in your code you are adding the RadTextBox to the ContentPanel of the first tab (TabItem1). Maybe you need to change the code

    from:

    Me.RadTabStrip1.SelectedTab = Me.RadTabStrip1.Items(itab)
    Me.TabItem1.ContentPanel.Controls.Add(txt)

    to

    Me.RadTabStrip1.SelectedTab = Me.RadTabStrip1.Items(itab)
    Me.RadTabStrip1.Items(itab).ContentPanel.Controls.Add(txt)
  3. UI for WinForms is Visual Studio 2017 Ready
  4. bobebs
    bobebs avatar
    7 posts
    Member since:
    May 2007

    Posted 04 May 2007 Link to this post

    Thanks for the reply, this does not work, I get an error
    "ContentPanel" is not a member of RadItem"
  5. surfer
    surfer avatar
    585 posts
    Member since:
    Jul 2003

    Posted 04 May 2007 Link to this post

    You may need to first cast the object - since the Items collection contains RadItem objects, you need to cast it to TabItem explicitly.

    Example:

    Dim currentTab As TabItem = DirectCast(Me.radTabStrip1.Items(itab), TabItem)
    currentTab.ContentPanel.Controls.Add(txt)
  6. bobebs
    bobebs avatar
    7 posts
    Member since:
    May 2007

    Posted 04 May 2007 Link to this post

    Thank you, thank you, thank you  --- this works
  7. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 07 May 2007 Link to this post

    Hi Bob Jackson,

    If you need further assistance we will be happy to help you with your issues.
    Thanks Matt for your correct responses.

    Greetings,
    Ray
    the telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top
UI for WinForms is Visual Studio 2017 Ready