How can I add specific controls to each of my tab?

C# how can you add a tab in a tabcontrol but preset what the tab contains and any coding within that tab?

  • I am trying to add a tab to my tab control but I already want these to contain Textboxes that are linked to my database. Please can someone help

  • Answer:

    You can't create new controls at runtime and be able to keep them there the next time the program is run. You will need to have the controls made at design time prior to the program being compiled/published. Instead of a tab control, consider using multiple forms.

Sam at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

There's a couple of ways you could save and re-create the tabs but I guess the simplest would be using Settings. Depending on what information you need to store to re-display the right data on each TabPage this might work: Assuming all you need to re-create the tabs is the database table name... Create a custom control which has the TextBox(s) you want to display. Depending on how you access your database in your application you want to modify the Constructor so it accepts either: 1. String - the name of the table the TextBox(s) should be linked to. or 2. The information already retrieved from the table. Whenever the "Add New" button is clicked: TabPage newPage = new TabPage(); newPage.Name = "newPage"; newPage.Text = "Tab text"; MyControl tabContent = new MyControl("table_name"); newPage.Controls.Add(tabContent); theTabControl.TabPages.Add(newPage); In your form's Closing event you'll want to loop over the tab pages and create a List of each one - storing the table name they link to. Then save that List as a Setting. When the application starts just load the List of table names and do the same as for "Add New"

Anthony

find what you like then go to file and hit new tab and duplicate it great way to go where you want theres no codeing

Russell

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.