I have a tab control that has many tabs. I only want to show 3 tabs to the user and which three depends on which combination of choices they make with some radio buttons. I decided that in the radio buttons when the user clicks I will call a function and that will pass some data to create the tab page. Below is what I thought could have worked but it seems that I am creating a brand new tab rather than showing one in the collection that I hid.
private void rdobtn_protocol_CheckedChanged(object sender, EventArgs e)
{
if (rdobtn_prot1.Checked) Showtab("tab_prot1");
if (rdobtn_prot2.Checked) Showtab("tab_prot2");
if (rdobtn_prot3 .Checked) Showtab("tab_prot3");
}
private void ShowTab(string tab)
{
tabControl1.SuspendLayout(); //Stop it running
tabControl1.TabPages.Clear(); // remove all the tabs
// Add controls in correct order
tabControl1.TabPages.Add(tab_control_centre); //always 1st tab
TabPage myTabPage = new TabPage(tab); //show the correct one
tabControl1.TabPages.Add(myTabPage);
tabControl1.TabPages.Add(tab_data_centre); //always last tab
tabControl1.ResumeLayout(); //Restart it running
}
Next I removed this
TabPage myTabPage = new TabPage(tab); //show the correct one
and changed this
tabControl1.TabPages.Add(tab);
Still no good I still create a new Tab. If I add the name direct as it is in the collection as below it works but then I cannot pass the string in. This will mean I have to hard code it and there are potentially a lot of tabs.
tabControl1.TabPages.Add(tab_prot1);
My question is how do I show tabs I have hidden by calling them in a function and passing in the "tab" I want to show. Hope that makes sense.