Click here to Skip to main content
15,888,301 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am wonderinf if it is possible to add a sub tab to a tab? If yes can someone tell me how?

As an example. I have two tabs such as feedbacks and reviews. Under the feedbacks tab I need to create two more tabs like Rules and Conenctions. Thanks a lot.
Posted

1 solution

You could put a child tab-control inside one of the tab-pages. That'd be basically equivalent to having sub-tabs.

[Edit]
--------

Here's what I quickly tried out using the designer. Added a tab-control with 2 tabs, and in the first tab, I added an inner tab control again with 2 tabs. The inner tab is docked to fill the entire page. Here's the auto generated code from VS 2010:

C#
#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
    this.outerTabControl = new System.Windows.Forms.TabControl();
    this.tabPageFeedback = new System.Windows.Forms.TabPage();
    this.tabPageReviews = new System.Windows.Forms.TabPage();
    this.innerTabControl = new System.Windows.Forms.TabControl();
    this.tabPageRules = new System.Windows.Forms.TabPage();
    this.tabPageConnections = new System.Windows.Forms.TabPage();
    this.outerTabControl.SuspendLayout();
    this.tabPageFeedback.SuspendLayout();
    this.innerTabControl.SuspendLayout();
    this.SuspendLayout();
    //
    // outerTabControl
    //
    this.outerTabControl.Controls.Add(this.tabPageFeedback);
    this.outerTabControl.Controls.Add(this.tabPageReviews);
    this.outerTabControl.Location = new System.Drawing.Point(73, 54);
    this.outerTabControl.Name = "outerTabControl";
    this.outerTabControl.SelectedIndex = 0;
    this.outerTabControl.Size = new System.Drawing.Size(317, 266);
    this.outerTabControl.TabIndex = 0;
    //
    // tabPageFeedback
    //
    this.tabPageFeedback.Controls.Add(this.innerTabControl);
    this.tabPageFeedback.Location = new System.Drawing.Point(4, 22);
    this.tabPageFeedback.Name = "tabPageFeedback";
    this.tabPageFeedback.Padding = new System.Windows.Forms.Padding(3);
    this.tabPageFeedback.Size = new System.Drawing.Size(309, 240);
    this.tabPageFeedback.TabIndex = 0;
    this.tabPageFeedback.Text = "Feedback";
    this.tabPageFeedback.UseVisualStyleBackColor = true;
    //
    // tabPageReviews
    //
    this.tabPageReviews.Location = new System.Drawing.Point(4, 22);
    this.tabPageReviews.Name = "tabPageReviews";
    this.tabPageReviews.Padding = new System.Windows.Forms.Padding(3);
    this.tabPageReviews.Size = new System.Drawing.Size(309, 240);
    this.tabPageReviews.TabIndex = 1;
    this.tabPageReviews.Text = "Reviews";
    this.tabPageReviews.UseVisualStyleBackColor = true;
    //
    // innerTabControl
    //
    this.innerTabControl.Controls.Add(this.tabPageRules);
    this.innerTabControl.Controls.Add(this.tabPageConnections);
    this.innerTabControl.Dock = System.Windows.Forms.DockStyle.Fill;
    this.innerTabControl.Location = new System.Drawing.Point(3, 3);
    this.innerTabControl.Name = "innerTabControl";
    this.innerTabControl.SelectedIndex = 0;
    this.innerTabControl.Size = new System.Drawing.Size(303, 234);
    this.innerTabControl.TabIndex = 0;
    //
    // tabPageRules
    //
    this.tabPageRules.Location = new System.Drawing.Point(4, 22);
    this.tabPageRules.Name = "tabPageRules";
    this.tabPageRules.Padding = new System.Windows.Forms.Padding(3);
    this.tabPageRules.Size = new System.Drawing.Size(295, 208);
    this.tabPageRules.TabIndex = 0;
    this.tabPageRules.Text = "Rules";
    this.tabPageRules.UseVisualStyleBackColor = true;
    //
    // tabPageConnections
    //
    this.tabPageConnections.Location = new System.Drawing.Point(4, 22);
    this.tabPageConnections.Name = "tabPageConnections";
    this.tabPageConnections.Padding = new System.Windows.Forms.Padding(3);
    this.tabPageConnections.Size = new System.Drawing.Size(295, 208);
    this.tabPageConnections.TabIndex = 1;
    this.tabPageConnections.Text = "Connections";
    this.tabPageConnections.UseVisualStyleBackColor = true;
    //
    // Form1
    //
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(433, 383);
    this.Controls.Add(this.outerTabControl);
    this.Name = "Form1";
    this.Text = "Form1";
    this.outerTabControl.ResumeLayout(false);
    this.tabPageFeedback.ResumeLayout(false);
    this.innerTabControl.ResumeLayout(false);
    this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.TabControl outerTabControl;
private System.Windows.Forms.TabPage tabPageFeedback;
private System.Windows.Forms.TabControl innerTabControl;
private System.Windows.Forms.TabPage tabPageRules;
private System.Windows.Forms.TabPage tabPageConnections;
private System.Windows.Forms.TabPage tabPageReviews;
 
Share this answer
 
v2
Comments
Orcun Iyigun 3-Nov-10 20:13pm    
If it is possible can you explain me how to do it? Should I add it from TabPages Collection Editor of the tabcontrol?
Orcun Iyigun 3-Nov-10 20:15pm    
Oh I made it :) It is fairly easy.
Nish Nishant 3-Nov-10 20:19pm    
Yeah, I've also updated my response with some sample code. But glad you got it working.

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