Solved

TabControl1.TabPages.Contains Problem in VB.NET

Posted on 2006-06-12
4
472 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 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