Solved

TabControl1.TabPages.Contains Problem in VB.NET

Posted on 2006-06-12
4
461 Views
Last Modified: 2012-06-21
Hey everyone I have a question that really bugging me. I read an example on msdn about how to check to see if a specified tab has already been created so I code the following

     'Bring up a new tab that lets you set the properties for that event
        Dim myTabPage As New TabPage
        myTabPage.Text = gridActiveEvent.Item(gridActiveEvent.CurrentCell.RowNumber, 2) & ":" & gridActiveEvent.Item(gridActiveEvent.CurrentCell.RowNumber, 0)

Debug.Write(myTabPage)
        'Make sure tab wasn't already created
       If TabControl1.TabPages.Contains(myTabPage) = False Then

            TabControl1.TabPages.Add(myTabPage)
            TabControl1.SelectedTab = (myTabPage)
        Else
            Exit Sub

        End If
     


The code doesn't work and a new tab is created even though the tab already exists. Debug.wrote wrote this

TabPage: {09003C6DD447D81C:0}

Both times i ran this code, the the tabs are the same.


Thanks in advance for the help guys.
0
Comment
Question by:JPERKS1985
  • 4
4 Comments
 
LVL 10

Accepted Solution

by:
vadim63 earned 500 total points
ID: 16889982
Dim myTabPage As New TabPage
Dim Check as Boolean
Dim PageText as String = gridActiveEvent.Item(gridActiveEvent.CurrentCell.RowNumber, 2) & ":" & gridActiveEvent.Item(gridActiveEvent.CurrentCell.RowNumber, 0)
        myTabPage.Text = PageText

      For i As Integer = 0 To Me.TabControl1.TabCount - 1
            If Me.TabControl1.TabPages(i).Text = PageText Then
                Check = True
            Else
                Check = False
            End If
        Next

Debug.Write(myTabPage)
        'Make sure tab wasn't already created
       If Check = False Then

            TabControl1.TabPages.Add(myTabPage)
            TabControl1.SelectedTab = (myTabPage)
        Else
            Exit Sub

        End If
0
 
LVL 10

Expert Comment

by:vadim63
ID: 16890063
It should be like this:

Dim myTabPage As New TabPage
Dim Check as Boolean
Dim PageText as String = gridActiveEvent.Item(gridActiveEvent.CurrentCell.RowNumber, 2) & ":" & gridActiveEvent.Item(gridActiveEvent.CurrentCell.RowNumber, 0)
        myTabPage.Text = PageText

      For i As Integer = 0 To Me.TabControl1.TabCount - 1
            If Me.TabControl1.TabPages(i).Text = PageText Then
                Check = True
                Exit For
            Else
                Check = False
            End If
        Next

Debug.Write(myTabPage)
        'Make sure tab wasn't already created
       If Check = False Then

            TabControl1.TabPages.Add(myTabPage)
            TabControl1.SelectedTab = (myTabPage)
        Else
            Exit Sub

        End If
0
 
LVL 10

Expert Comment

by:vadim63
ID: 16890068
After "Check = True", should be: "Exit For"
0
 
LVL 10

Expert Comment

by:vadim63
ID: 16890244
Or like this:

Private Function CheckIt(ByVal pText As String) As Boolean
        For i As Integer = 0 To Me.TabControl1.TabCount - 1
            If Me.TabControl1.TabPages(i).Text = pText Then
                CheckIt = True
                Exit For
            Else
                CheckIt = False
            End If
        Next
    End Function

Dim myTabPage As New TabPage
Dim PageText as String = gridActiveEvent.Item(gridActiveEvent.CurrentCell.RowNumber, 2) & ":" & gridActiveEvent.Item(gridActiveEvent.CurrentCell.RowNumber, 0)
        myTabPage.Text = PageText

Debug.Write(myTabPage)
        'Make sure tab wasn't already created
       If CheckIt(myTabPage.Text) = False Then
            TabControl1.TabPages.Add(myTabPage)
            TabControl1.SelectedTab = (myTabPage)
        End If
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question