Click here to Skip to main content
15,889,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I;m trying to programatically code a tabcontrol within a tabcontrol.

Here is what it is supposed to look like:

Outer tabcontrol:
[Dashboard] [Sync Job 1]

Then under the Sync Job 1 tabPage I'm trying to show this tabPage:

[Destination]

So, I have an outer tabcontrol and then an inner tabcontrol. Once I understand how these two controls nest and I can display them, I will add a few more tabPages to the inner tabcontrol.

My code below, when I click on the Sync Job 1 tabPage does not show the Destination tabPage on the inner tabcontrol.

Thanks for any help...

C#
TabPage dashboardTabPage = new TabPage("Dashboard Summary");
TabControl maintc = new TabControl();
int tcLeft = groupBoxDashboardSummary.Left + 4;
int tcTop = groupBoxDashboardSummary.Top + 20;
int tcHeight = groupBoxDashboardSummary.Height - 25;
int tcWidth = groupBoxDashboardSummary.Width - 6;
maintc.Location = new Point(tcLeft, tcTop);
maintc.Height = tcHeight;
maintc.Width = tcWidth;
maintc.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right);
maintc.TabPages.Add(dashboardTabPage);
this.Controls.AddRange(new Control[] { maintc });

TabPage syncJobTabPage = new TabPage(syncJobTitle);
maintc.TabPages.Add(syncJobTabPage);
TabPage destinationTabPage = new TabPage("Destination");
TabControl tcSync = new TabControl();
int tcSyncLeft = groupBoxDashboardSummary.Left + 14;
int tcSyncTop = groupBoxDashboardSummary.Top + 40;
int tcSyncHeight = groupBoxDashboardSummary.Height - 45;
int tcSyncWidth = groupBoxDashboardSummary.Width - 16;
tcSync.Location = new Point(tcSyncLeft, tcSyncTop);
tcSync.Height = tcSyncHeight;
tcSync.Width = tcSyncWidth;
tcSync.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right);
tcSync.TabPages.Add(destinationTabPage);
this.Controls.AddRange(new Control[] { tcSync });
maintc.BringToFront();
Posted

1 solution

Hi rfresh,

I found solution for your query, try the below code it's working for me.

C#
TabPage dashboardTabPage = new TabPage("Dashboard Summary");
            TabControl maintc = new TabControl();
           // maintc.Width = this.Width;
          //  maintc.Height = this.Height;
           // int tcLeft = groupBoxDashboardSummary.Left + 4;
           // int tcTop = groupBoxDashboardSummary.Top + 20;
           // int tcHeight = groupBoxDashboardSummary.Height - 25;
           // int tcWidth = groupBoxDashboardSummary.Width - 6;
           // maintc.Location = new Point(tcLeft, tcTop);
           // maintc.Height = tcHeight;
           // maintc.Width = tcWidth;
            maintc.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right);
            maintc.TabPages.Add(dashboardTabPage);
            this.Controls.AddRange(new Control[] { maintc });

            TabPage syncJobTabPage = new TabPage("syncJobTitle");
            maintc.TabPages.Add(syncJobTabPage);



            TabPage destinationTabPage = new TabPage("Destination");
            TabControl tcSync = new TabControl();
           // int tcSyncLeft = groupBoxDashboardSummary.Left + 14;
            //int tcSyncTop = groupBoxDashboardSummary.Top + 40;
            //int tcSyncHeight = groupBoxDashboardSummary.Height - 45;
           // int tcSyncWidth = groupBoxDashboardSummary.Width - 16;
           // tcSync.Location = new Point(tcSyncLeft, tcSyncTop);
           // tcSync.Height = tcSyncHeight;
            //tcSync.Width = tcSyncWidth;
            tcSync.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right);
            tcSync.TabPages.Add(destinationTabPage);
            this.Controls.AddRange(new Control[] { tcSync });
            //maintc.BringToFront();

            syncJobTabPage.Controls.Add(tcSync); // Add this line to your coding.



i hope this will help you.

Thank's
Mohan G
 
Share this answer
 
v2
Comments
rfresh 4-Sep-13 1:44am    
Thank you for your help.

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