Click here to Skip to main content
15,894,106 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am working on a project in Windows Forms Application in C# wherein on clicking LOAD button a NEW TABPAGE is created with textboxes,labels,treeView loaded with data. This new TabPage is to be opened in a separate TabPage and not on the current window.
The point is i am totally new to Windows forms development and i don't know how to accomplish the above task.
If you can either redirect me to some fine tutorials or to some code snippets ,then it will be of great help.
thanks in advance!!!
Posted
Updated 25-Apr-14 0:53am
v2
Comments
johannesnestler 25-Apr-14 6:50am    
hard to tell where you stuck, what do you mean with "this sort of development"? - creating controls dynamically? Binding the controls to your data? Creating the TabPage? Finding the correct TabControl? Guessing, guessing... maybe update your question? Another small "advice": If you are talking about "tech" things like controls, use the correct names - there is no such thing like "Tab" in .NET Forms - there is a TabControl a TabPage... if in doubt give the full name (with namespace)
BillWoodruff 25-Apr-14 11:10am    
What is on your Main Form ? Is there one TabControl on the Main Form, and when you click 'Load you want to open a new TabPage with Controls in that TabControl ? Or, do you want to open a new Form with a TabControl ? Or, open new Forms, each of which has a TabControl ?
gggustafson 25-Apr-14 13:33pm    
Expanding on BillWoodruff's question: what do you mean by "opened in a separate TabPage and not on the current window"? Are you willing to have a new TabPage open in the current TabControl?
sovit agarwal 28-Apr-14 4:42am    
Hi Bill!!!
Yes,the MainForm does have a TabControl and when i click on LOAD i want to open a new TabPage with Controls within that same TabControl. No new forms will be created.

1 solution

Dynamically creating a new tab in a TabControl is pretty simple.

Here is some code to put in your button_Click() :
C#
// Instanciate a TabPage
TabPage myTab = new TabPage("My TabPage");
            
// If you want to create your controls manually, then here we go...
Label myLabel = new Label();
myLabel.Text = "This is a label";

// Add your controls in it
myTab.Controls.Add(myLabel);

// Don't forget to add your TabPage in the TabPageCollection
tabControl1.TabPages.Add(myTab);

This is kinda weird to instantiate your controls manually though, you may want to create a UserControl instead.
After created your UserControl, you can easily add it to your TabPage the same way :
C#
myTab.Controls.Add(new MyUserControl());

If you create your controls manually, you should know how to populate them, however, if you decide to use a UserControl, pass an ID or an entity as a parameter to your UserControl constructor and populate it.
 
Share this answer
 

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