Solved

TabControl1.TabPages.Contains Problem in VB.NET

Posted on 2006-06-12
4
425 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now