在每个新的相同TabPages中填充Datagridview [英] Fill Datagridview in each new identical TabPages
问题描述
我有TabControl和1个TabPages并包含DataGridView。我从TabPages1创建TabPages2,代码为:
I have TabControl with 1 TabPages and contains DataGridView. I create TabPages2 from TabPages1 with code :
Dim Frm As New TabFormPage
Dim MoreTabs As TabPage = Frm.TabPage1
Dim i As Integer
For i = 1 To TabControl1.TabPages.Count
MoreTabs.Text = "TabPage" & i + 1
Next i
TabControl1.Controls.Add(MoreTabs)
Frm.Dispose()
TabPages2控件与TabPages1相同
如果我在TabPages1中使用BackgroundWorker填充DataGridView,它工作。但是如果我在不同来源的每个新TabPages(例如TabPages2)中填充DataGridView,它就无法工作(TabPages2中的DataGridView /每个New TabPages都是空的/什么都没有)。它总是填充Tabpages1 DataGridView
如何用相同的控件填充每个New TabPages中的每个DataGridView?这是填写DataGridview的代码:
TabPages2 Controls identical to TabPages1
If I fill DataGridView with BackgroundWorker in TabPages1 , it was working . But if I fill DataGridView in every New TabPages ( eg TabPages2 ) from different sources , it was not working (DataGridView in TabPages2/each New TabPages is empty/nothing) . It always fills Tabpages1 DataGridView
How to fill every DataGridView in every New TabPages with identical controls ? Here's my code to fill 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
DataGridView1.DataSource = DtSet.Tables(0)
dv = DtSet.Tables(0).DefaultView
MaxRecords = DtSet.Tables(0).Rows.Count
MyConnection.Close()
DataGridView1.Columns("F20").Visible = False
DataGridView1.Columns("F21").Visible = False
DataGridView1.Columns("F22").Visible = False
End Sub
感谢您的帮助
Thanks for your help
推荐答案
这些标签页比你知道的更相同。
你没有复制TabPage1和它的内容。您获得了对TabPage的引用并将每个标签页设置为页面上的SAME TabPage1和SAME控件!
您必须创建一个新的TabPage和New DataGridView for每个标签页。您还必须为每个页面和控件设置每个属性。
Those tab pages are more identical than you know.
You're not making a copy of TabPage1 and its contents. You getting a reference to the TabPage and setting each tab page to the SAME TabPage1 and SAME controls on the page!
You have to create a New TabPage and New DataGridView for each tab page. You also have to setup the properties of each however you want for each page and control.
这篇关于在每个新的相同TabPages中填充Datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!