I have some code that creates a tabcontrol, adds as many tabpages as will be needed and places a datagridview on each tabpage. The datasource does actually hold data, but nothing is being displayed in the datagridview.... Can you tell me what I'm missing or doing wrong?
Code:
strDBLocation = My.Settings.strDatabaseLocation
conn.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = " & strDBLocation
Dim objCmd As New OleDb.OleDbCommand
Dim strName As String
strName = "GRAND & REHBERG"
objCmd.Connection = conn
objCmd.CommandType = CommandType.Text
If m_da Is Nothing Then m_da = New OleDb.OleDbDataAdapter
m_da.SelectCommand = objCmd
conn.Open()
objCmd.CommandText = "SELECT DISTINCT Corner FROM tblWork WHERE Intersection = '" & strName & "' And Project = '" & m_Project & "' ORDER BY Corner"
m_da.Fill(m_Dataset, "tblCorners")
For i = New Int16 To m_Dataset.Tables("tblCorners").Rows.Count - 1
objCmd.CommandText = "SELECT WorkItem As Item, Description, " _
& "Length_Est As Length, Width_Est As Width, Quantity_Est As Quantity, UnitPrice_Est As Price, " _
& "EstimatedCost As Cost FROM tblWork WHERE Intersection = '" _
& strName & "' And Corner = '" & m_Dataset.Tables("tblCorners").Rows(i)(0).ToString _
& "' And Project = '" & m_Project & "'"
m_da.Fill(m_Dataset, "CornerNum" & i)
Next
'MsgBox(m_Dataset.Tables("CornerNum" & 0).Rows(0)(0).ToString & vbNewLine _
' & m_Dataset.Tables("CornerNum" & 0).Rows(0)(1).ToString & vbNewLine _
' & m_Dataset.Tables("CornerNum" & 0).Rows(0)(2).ToString & vbNewLine _
' & m_Dataset.Tables("CornerNum" & 0).Rows(0)(3).ToString, MsgBoxStyle.Information, "DeBug:")
'CREATE NEW TABCONTROL ON LAST TAB PAGE....
Dim tabctrl As New TabControl
tabctrl.Location = New Point(75, 75)
tabctrl.Height = 400
tabctrl.Width = 700
tabctrl.Name = "TabControl2"
Me.TabControl1.Controls.Item(4).Controls.Add(tabctrl)
For i = New Int16 To m_Dataset.Tables("tblCorners").Rows.Count - 1
tabctrl.Controls.Add(New TabPage)
tabctrl.Controls.Item(i).Text = m_Dataset.Tables("tblCorners").Rows(i)(0).ToString
tabctrl.Controls.Item(i).Name = m_Dataset.Tables("tblCorners").Rows(i)(0).ToString
Dim dgv As New DataGridView
dgv.Height = 260
dgv.Width = 650
dgv.Location = New Point(10, 10)
tabctrl.Controls.Item(i).Controls.Add(dgv)
dgv.Name = m_Dataset.Tables("tblCorners").Rows(i)(0).ToString
dgv.DataSource = m_Dataset.Tables("CornerNum" & i)
dgv.Columns("Price").DefaultCellStyle.Format = "c"
dgv.Columns("Cost").DefaultCellStyle.Format = "c"
dgv.Columns.Item("Item").Width = 45
dgv.Columns.Item("Description").Width = 236
dgv.Columns.Item("Length").Width = 50
dgv.Columns.Item("Width").Width = 50
dgv.Columns.Item("Quantity").Width = 70
dgv.Columns.Item("Price").Width = 70
dgv.Columns.Item("Cost").Width = 85
Next
'CLEAN UP THE DATASETS SO THEY ARE EMPTY WHEN USED AGAIN...
For i = New Int16 To m_Dataset.Tables("tblCorners").Rows.Count - 1
m_Dataset.Tables("CornerNum" & i).Clear()
Next
m_Dataset.Tables("tblCorners").Clear()
m_da.Dispose()
objCmd.Dispose()
conn.Close()
conn.Dispose()