0

I have hard-coded a tabcontrol, which loads a bunch of data for me to use, but I want to be able to throw the tabcontrol away and recreate the same one that I hard-coded, but blank without any input.

Right now I have a simple tabControl with about 10-15 pages and about 10 controls on each which vary from TextBoxes to all kinds of controls.

I've tried doing it simple and just removing and recreating the control with 2 simple lines like:

this.Controls.Remove(tabControl1);
this.Controls.Add(tabControl1);

Which works fine with removing and recreating the tabControl but it doesn't recreate the controls inside returning the value to the originals.

I have a working version which just removes the tabControl and resets every child control to custom value but this seems a but to ugly and hacked for what I'm looking for.

Is there some way or creating a template of the tabControl and call a new one every time?

LittleBobbyTables - Au Revoir
  • 32,008
  • 25
  • 109
  • 114
Pelle Nilsson
  • 19
  • 1
  • 4
  • Open the .designer file to see how the tab control is created in code. Learn how NOT to do UI by looking at your code. Maybe make some user controls instead. 15 pages x 10 controls each is NOT a simple tab control - it's a bloated one. – Sten Petrov Feb 27 '13 at 14:54
  • `Is there some way or creating a template of the tabControl and call a new one every time?` - winforms doesn't have the concept of Templates, you'd better switch to WPF, which truly enables the separation of UI and Data. – Federico Berasategui Feb 27 '13 at 15:10
  • The tab control is simple, the tab pages are not. The thing is that i dont wanna have to recreate all the controls in the tab control, i want to have a finish tab control wich i can just summon and trash whenever i want. Or will i have to recreate the tab control and all controls within it before i summon the new one? – Pelle Nilsson Feb 27 '13 at 16:34
  • @PelleNilsson which part of my comment didn't you understand? regardless of using winforms or WPF or anything else, you need to understand that UI is NOT Data. program your application in such a way that data is kept separated from UI and you will not have these kind of issues. – Federico Berasategui Feb 27 '13 at 16:49
  • @HighCore I did understand your comment... The reason I'm not using WPF is because i don't know it good enough. And I've been programing my application UI completely separated form data. I don't think you understand the problem correctly, i have made one tab control UI, in c# express~ and 2 buttons(a lot more but that's not relevant). When i press the first button i want to create an new instance of the tab control which i already made in the editor, can for example add it by typing; this.Controls.Add(tabControl1); And when i press the second button i want to scrap the tab control. – Pelle Nilsson Feb 27 '13 at 19:45
  • so if i click the first button again it will create another NEW instance of the tab controller with new texboxes etc. – Pelle Nilsson Feb 27 '13 at 19:49
  • Then you should be able to create a new instance of the UI stuff with a new instance of the data stuff, to show an "empty" UI. – Federico Berasategui Feb 27 '13 at 19:50
  • Can i somehow add the controls to some invisible group and when i scrap the tab controller i also dispose all the controls in this invisible group so new once get created once the tab control is recreated(instead of using the old controls which got user input in em) – Pelle Nilsson Feb 27 '13 at 19:50
  • @HighCore exactly, so back to the topic, how does one do this? I've gotten so far so that if i dispose every control in the form and initiate components again the controls will be resetted, but then i dispose and recreate every control, i wanna do this but only will the controls childs of the tab control so like a foreach loop that goes through the tab control, saves all the control names in an array, disposes all child controls and recreates controls from the array? – Pelle Nilsson Feb 27 '13 at 19:51
  • What about placing all your UI stuff inside a UserControl and then creating a new instance of that for each Tab Item? – Federico Berasategui Feb 27 '13 at 19:53
  • yes... this UserControl looks like something i mean... – Pelle Nilsson Feb 27 '13 at 19:57

0 Answers0