我有一个包含datagridview的克隆标签页。 我厌倦了在每个标签页中填写datagridview,因为它只填写tabpage1
这是我使用按钮克隆选项卡的代码:
Private Sub NewTab_Click(sender As Object, e As EventArgs) Handles NewTab.Click
Dim Frm As New NewTabPage
Dim MoreTabs As TabPage = Frm.TabPage1
Dim i As Integer ' = 1
For i = 1 To TabControl1.TabPages.Count
MoreTabs.Text = "TabPage" & i + 1
Next i
TabControl1.Controls.Add(MoreTabs)
Frm.Dispose()
End Sub
这是我用backgroundworker填充datagridview的代码:
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FPathTab + ";Extended Properties=Excel 12.0;")
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [" & CSheetTab1 & "]'", MyConnection)
DtSet = New System.Data.DataSet
DtSet.Clear()
MyCommand.Fill(DtSet)
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
Me.TabControl1.TabPages(TabControl1.SelectedIndex).Text = Trim("Asset" & CTabName & " 20" & CTabName1)
Me.DataGridView1.DataSource = DtSet.Tables(0)
dv = DtSet.Tables(0).DefaultView
End Sub
请帮助,如何使用每个标签的不同数据填充datagridview?