Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have TabControl with 1 TabPages and contains DataGridView. I create TabPages2 from TabPages1 with code :
VB
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 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 :
VB
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
Posted

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900