DataBinding in second, third…TabPages

I have experience in few months ago. I was working on a WinForm application. I placed a TabControl with multiple TabPages. However, I found out that the dataBinding does not work on the second, third or later TabPage controls. After getting some error and test. I found out that the controls in these tabPage are not being loaded until it is “showed”.

 

So I have some code sample to resolve this, you may try to place it under Page.Load event handling,


    foreach (TabPage tp in tabControl1.TabPages)
    {
        tp.Show();
    }
    this.tabControl1.SelectedTab = this.tabPage2;

 

// here I am going to make sure that the dataBinding is completed before select into other tabPages.
// You may try to loop this one by one tabPage if you have more tabPages
    this.tabPage2.BindingContextChanged += (object sender, EventArgs e) => {
        this.tabControl1.SelectedTab = this.tabPage1;
    };

    this.tabControl1.SelectedTab = this.tabPage1;


Hope this article could help you a bit.