Click here to Skip to main content
15,884,974 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi i took user contol, I took all controls and I added tab contol
for dynamically adding all data through user control
I wrote the code in tab control but it's not working.

Where can i write that code
C#
void AddTab()
{
    TabPage tbp = new TabPage();
   
                tbp.Name=tabControl1.TabPages.Count.ToString();
UserControl1 cnt=new UserControl1();

   
                cnt.Name="Cnt" + tbp.Name;
    cnt.Dock=DockStyle.Fill;
    tbp.Controls.Add(cnt);
}

?
Posted
Updated 6-Apr-14 23:57pm
v3

1 solution

you are adding usercontrol in tabpage...
but you miss adding tabpage in tabcontrol1
C#
void AddTab()
{
    TabPage tbp = new TabPage();

    tbp.Name = tabControl1.TabPages.Count.ToString();
    UserControl1 cnt = new UserControl1();

    cnt.Name = "Cnt" + tbp.Name;
    cnt.Dock = DockStyle.Fill;
    tbp.Controls.Add(cnt); //you are adding usercontrol in tab page
                
    tabControl1.TabPages.Add(tbl); //but you miss adding tabpage in tabcontrol1
}

Happy Coding!
:)
 
Share this answer
 
Comments
hilbert hussen 7-Apr-14 2:53am    
where can i add this code ..in usecontrol or in tabcontrol
Aarti Meswania 7-Apr-14 2:58am    
just add underlined line in Addtab() method as I did
hilbert hussen 7-Apr-14 3:05am    
private void UserControl1_Load(object sender, EventArgs e)
{
void AddTab()
{
TabPage tbp = new TabPage();

tbp.Name=tabControl1.TabPages.Count.ToString();
UserControl1 cnt=new UserControl1();


cnt.Name="Cnt" + tbp.Name;
cnt.Dock=DockStyle.Fill;
tbp.Controls.Add(cnt);
tabControl1.TabPages.Add(tabPage1);
}
}
}

not working

please help

i take user control i add all controls..now i take form in that i take tab control
i write that code in userconrol


still not 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