JPERKS1985
asked on
TabControl1.TabPages.Contains Problem in VB.NET
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(gridA ctiveEvent .CurrentCe ll.RowNumb er, 2) & ":" & gridActiveEvent.Item(gridA ctiveEvent .CurrentCe ll.RowNumb er, 0)
Debug.Write(myTabPage)
'Make sure tab wasn't already created
If TabControl1.TabPages.Conta ins(myTabP age) = False Then
TabControl1.TabPages.Add(m yTabPage)
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.
'Bring up a new tab that lets you set the properties for that event
Dim myTabPage As New TabPage
myTabPage.Text = gridActiveEvent.Item(gridA
Debug.Write(myTabPage)
'Make sure tab wasn't already created
If TabControl1.TabPages.Conta
TabControl1.TabPages.Add(m
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
After "Check = True", should be: "Exit For"
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(gridA ctiveEvent .CurrentCe ll.RowNumb er, 2) & ":" & gridActiveEvent.Item(gridA ctiveEvent .CurrentCe ll.RowNumb er, 0)
myTabPage.Text = PageText
Debug.Write(myTabPage)
'Make sure tab wasn't already created
If CheckIt(myTabPage.Text) = False Then
TabControl1.TabPages.Add(m yTabPage)
TabControl1.SelectedTab = (myTabPage)
End If
Private Function CheckIt(ByVal pText As String) As Boolean
For i As Integer = 0 To Me.TabControl1.TabCount - 1
If Me.TabControl1.TabPages(i)
CheckIt = True
Exit For
Else
CheckIt = False
End If
Next
End Function
Dim myTabPage As New TabPage
Dim PageText as String = gridActiveEvent.Item(gridA
myTabPage.Text = PageText
Debug.Write(myTabPage)
'Make sure tab wasn't already created
If CheckIt(myTabPage.Text) = False Then
TabControl1.TabPages.Add(m
TabControl1.SelectedTab = (myTabPage)
End If
Dim myTabPage As New TabPage
Dim Check as Boolean
Dim PageText as String = gridActiveEvent.Item(gridA
myTabPage.Text = PageText
For i As Integer = 0 To Me.TabControl1.TabCount - 1
If Me.TabControl1.TabPages(i)
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(m
TabControl1.SelectedTab = (myTabPage)
Else
Exit Sub
End If