Crazyj
07-03-2004, 10:32 AM
Hello,
I have a form with two combo boxes, a button, and a Tab Control (with no tab pages) created a design time. The first combobox (cboProject) populates the tab page on the parent tab control with it's selected text. It also provides the parameter for the select query to fill a dataset and populate the second combo box(cboAddress). cboAddress is meant to populate tab pages on the second tabcontrol created at run time. The button triggers the event that makes all of the above happen (except the population of cboAddress).
Now the problem I have is adding addition tabs to the child tabcontrol. Since it's created at run time I have to create a "new" instance of it every time I try to access it. I need to be able to access the current instance of the control to add pages to it.
hopefully my code is easier to understand than explaination.
Private Sub cboProject_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboProject.SelectedIndexChanged
Try
Dim i As Integer
Dim dslots1 As New DataSet
Dim daAddr As New SqlDataAdapter
Dim item As Object = cboProject.SelectedValue
Dim tp1 As New TabPage
Dim tcAddress As AddTabLayer
Dim bnA As Boolean = False
Dim selAddress As String = "SELECT Address FROM tblDrawInspections " & _
"WHERE ProjectName = '" & CType(item, String) & "'"
daAddr.SelectCommand = New SqlCommand(selAddress, cnn)
daAddr.SelectCommand.CommandType = CommandType.Text
daAddr.Fill(dslots1, "tblAddress")
cboAddress.Items.Clear()
cboAddress.Update()
For Each l As DataRow In dslots1.Tables("tblAddress").Rows
cboAddress.Items.Add(l.Item("Address"))
Next
Catch ex As ArgumentOutOfRangeException
Exit Try
Catch ex As Exception
MessageBox.Show(Err.Description)
End Try
End Sub
Private Sub btnGetProperty_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetProperty.Click
Dim i As Integer
Dim dslots1 As New DataSet
Dim daAddr As New SqlDataAdapter
Dim item As Object = cboProject.SelectedValue
Dim lot As Object = cboAddress.SelectedItem
Dim tp1 As New TabPage
Dim tp2 As New TabPage
Dim tcAddress As New TabControl
Dim bnA As Boolean = False
tp1.Text = CType(item, String)
tp2.Text = CType(lot, String)
'Creates a new tab with child tabcontrol if none exists
If tbcProjectLayer.TabPages.Count = 0 Then
tbcProjectLayer.TabPages.Add(tp1)
tcAddress.Dock = DockStyle.Fill
tcAddress.Alignment = TabAlignment.Bottom
tcAddress.TabPages.Add(tp2)
tcAddress.Visible = True
tbcProjectLayer.TabPages.Item(0).Controls.Add(tcAddress)
Exit Sub
End If
'Loops through parent tab controls tabs
For i = 0 To tbcProjectLayer.TabPages.Count - 1
'If statement to prevent creation of a duplicate tab
If tbcProjectLayer.TabPages.Item(i).Text = tp1.Text Then
'Supposed to loop through tabs on child tab control of parent item(i)
' and exit procedure if match is found or create new tab if not found.
For s As Integer = 0 To tcAddress.TabPages.Count - 1
If tcAddress.TabPages.Item(s).Text = tp2.Text Then
Exit Sub
Else
tcAddress.TabPages.Add(tp2)
End If
Next
bnA = True
Exit For
End If
Next i
'Creates new tab page on parent tab control with new child tab control with one tab
If bnA = False Then
tbcProjectLayer.TabPages.Add(tp1)
tcAddress.Dock = DockStyle.Fill
tcAddress.Alignment = TabAlignment.Bottom
tcAddress.TabPages.Add(tp2)
tcAddress.Visible = True
tbcProjectLayer.TabPages.Item(tbcProjectLayer.TabPages.Count - 1).Controls.Add(tcAddress)
End If
End Sub
This is the section that doesn't work, as I'm trying to access the child tabcontrol with a new instance of the control
If tbcProjectLayer.TabPages.Item(i).Text = tp1.Text Then
'Supposed to loop through tabs on child tab control of parent item(i)
' and exit procedure if match is found or create new tab if not found.
For s As Integer = 0 To tcAddress.TabPages.Count - 1
If tcAddress.TabPages.Item(s).Text = tp2.Text Then
Exit Sub
Else
tcAddress.TabPages.Add(tp2)
End If
Next
Thanks in advance.
I have a form with two combo boxes, a button, and a Tab Control (with no tab pages) created a design time. The first combobox (cboProject) populates the tab page on the parent tab control with it's selected text. It also provides the parameter for the select query to fill a dataset and populate the second combo box(cboAddress). cboAddress is meant to populate tab pages on the second tabcontrol created at run time. The button triggers the event that makes all of the above happen (except the population of cboAddress).
Now the problem I have is adding addition tabs to the child tabcontrol. Since it's created at run time I have to create a "new" instance of it every time I try to access it. I need to be able to access the current instance of the control to add pages to it.
hopefully my code is easier to understand than explaination.
Private Sub cboProject_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboProject.SelectedIndexChanged
Try
Dim i As Integer
Dim dslots1 As New DataSet
Dim daAddr As New SqlDataAdapter
Dim item As Object = cboProject.SelectedValue
Dim tp1 As New TabPage
Dim tcAddress As AddTabLayer
Dim bnA As Boolean = False
Dim selAddress As String = "SELECT Address FROM tblDrawInspections " & _
"WHERE ProjectName = '" & CType(item, String) & "'"
daAddr.SelectCommand = New SqlCommand(selAddress, cnn)
daAddr.SelectCommand.CommandType = CommandType.Text
daAddr.Fill(dslots1, "tblAddress")
cboAddress.Items.Clear()
cboAddress.Update()
For Each l As DataRow In dslots1.Tables("tblAddress").Rows
cboAddress.Items.Add(l.Item("Address"))
Next
Catch ex As ArgumentOutOfRangeException
Exit Try
Catch ex As Exception
MessageBox.Show(Err.Description)
End Try
End Sub
Private Sub btnGetProperty_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetProperty.Click
Dim i As Integer
Dim dslots1 As New DataSet
Dim daAddr As New SqlDataAdapter
Dim item As Object = cboProject.SelectedValue
Dim lot As Object = cboAddress.SelectedItem
Dim tp1 As New TabPage
Dim tp2 As New TabPage
Dim tcAddress As New TabControl
Dim bnA As Boolean = False
tp1.Text = CType(item, String)
tp2.Text = CType(lot, String)
'Creates a new tab with child tabcontrol if none exists
If tbcProjectLayer.TabPages.Count = 0 Then
tbcProjectLayer.TabPages.Add(tp1)
tcAddress.Dock = DockStyle.Fill
tcAddress.Alignment = TabAlignment.Bottom
tcAddress.TabPages.Add(tp2)
tcAddress.Visible = True
tbcProjectLayer.TabPages.Item(0).Controls.Add(tcAddress)
Exit Sub
End If
'Loops through parent tab controls tabs
For i = 0 To tbcProjectLayer.TabPages.Count - 1
'If statement to prevent creation of a duplicate tab
If tbcProjectLayer.TabPages.Item(i).Text = tp1.Text Then
'Supposed to loop through tabs on child tab control of parent item(i)
' and exit procedure if match is found or create new tab if not found.
For s As Integer = 0 To tcAddress.TabPages.Count - 1
If tcAddress.TabPages.Item(s).Text = tp2.Text Then
Exit Sub
Else
tcAddress.TabPages.Add(tp2)
End If
Next
bnA = True
Exit For
End If
Next i
'Creates new tab page on parent tab control with new child tab control with one tab
If bnA = False Then
tbcProjectLayer.TabPages.Add(tp1)
tcAddress.Dock = DockStyle.Fill
tcAddress.Alignment = TabAlignment.Bottom
tcAddress.TabPages.Add(tp2)
tcAddress.Visible = True
tbcProjectLayer.TabPages.Item(tbcProjectLayer.TabPages.Count - 1).Controls.Add(tcAddress)
End If
End Sub
This is the section that doesn't work, as I'm trying to access the child tabcontrol with a new instance of the control
If tbcProjectLayer.TabPages.Item(i).Text = tp1.Text Then
'Supposed to loop through tabs on child tab control of parent item(i)
' and exit procedure if match is found or create new tab if not found.
For s As Integer = 0 To tcAddress.TabPages.Count - 1
If tcAddress.TabPages.Item(s).Text = tp2.Text Then
Exit Sub
Else
tcAddress.TabPages.Add(tp2)
End If
Next
Thanks in advance.