?
Solved

TabControl1.TabPages.Contains Problem in VB.NET

Posted on 2006-06-12
4
Medium Priority
?
508 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

766 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