designating tabpage based on name. "toString" not possible.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: designating tabpage based on name. "toString" not possible.

  1. #1
    Join Date
    Mar 2011
    Posts
    153

    designating tabpage based on name. "toString" not possible.

    I am trying to figure out how to change the tab selected in a tabcontrol and tell the program which tab to select based on its' name. The problem is that the tab would be added programmatically in runtime. The error report says

    "Value of type 'String' cannot be converted to 'System.Windows.Forms.TabPage'. "

    What can I do?


    Code:
    Private Sub CatBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CatBtn1.Click
            TC2.SelectedTab = Me.Text
        End Sub
    
        Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
            y = y + 24
    
            Dim NTP As New TabPage()
            TC2.Controls.Add(NTP)
            NTP.Width = 75
    
            Dim NCB As New CatBtn()
            NCB.Location = New Point(0, y)
    
            Panel1.Controls.Add(NCB)
    
    
            Dim NLV As New ListView()
            NLV.Dock = DockStyle.Fill
            NLV.Items.Add("item 1")
            NLV.Items.Add("item 2")
    
    
            Label2.Text = y
    
            NTP.Text = TextBox2.Text
            NCB.Text = TextBox2.Text
            TextBox2.Text = ""
        End Sub
    BTW, I failed to mention this in my last post. I know I went on a long hiatus. I was designing someone's website with flash cs5.

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,090

    Re: designating tabpage based on name. "toString" not possible.

    You're going to have to loop through all the tabpages inside the Tabcontrol, and then test the name property

    Something like :

    Code:
          For Each tb As TabPage In TabControl1.TabPages
                If tb.Name = TextBox1.Text Then
                    TabControl1.SelectedTab = tb
                End If
            Next
    The names might be case sensitive. This may be an option to you

    BTW, I took a hiatus a while back - it's incredible how you miss this place when you're gone

  3. #3
    Join Date
    Aug 2009
    Location
    NW USA
    Posts
    173

    Re: designating tabpage based on name. "toString" not possible.

    Code:
    TC2.SelectedTab = TC2.TabPages(Me.Text)

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,090

    Re: designating tabpage based on name. "toString" not possible.

    Quote Originally Posted by Mur16 View Post
    Code:
    TC2.SelectedTab = TC2.TabPages(Me.Text)


    Seems like I was under the influence when I posted. Good job !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center