Dynamically adding controls to tabcontrol

E

Earl

I'm trying to dynamically position a combo and label on a tabcontrol. The
old Infragistics tabcontrol made this easy, but I'm trying to do it with
VS2005 common controls. Well, I cannot dynamically add a control to a
tabcontrol directly -- as the message says, "Cannot add 'ComboBox' to
TabControl. Only TabPages can be directly added to TabControls."

Sooooo .. what I am doing instead is to Add and Remove the combo and label
to each of the 8 tabpages as the tab is selected. This I *can* do, but I'm
not sure if this is the correct or best approach -- just one that works.
What I'm doing is to only create the combo and label in code, not in the
designer. I instantiate the control in the InitializeComponent then as each
tabpage selection is made, Add the combo to the tabpage and ALSO Remove the
combo from ALL the other tabpages. Any thoughts from anyone who has been
through this? Is there a better way?

switch (tabControl1.SelectedTab.Name.ToString())
{
case "tabW":
this.tabW.Controls.Add(this.cmbWidgets);
this.tabC.Controls.Remove(this.cmbWidgets);
this.tabS.Controls.Remove(this.cmbWidgets);
....
}
 
G

Guest

This is why people pay infragistics money. The standard control doesn have
the shared controls page so this is what you have to do if you want the
control in the tab page. It might be better, depening on your UI, if you put
the controls on a panel next to it or have it hover over the tabcontrol
rather than be in it.


Ciaran O'Donnell
 
E

Earl

How would you "hover"?

Ciaran O''Donnell said:
This is why people pay infragistics money. The standard control doesn have
the shared controls page so this is what you have to do if you want the
control in the tab page. It might be better, depening on your UI, if you
put
the controls on a panel next to it or have it hover over the tabcontrol
rather than be in it.


Ciaran O'Donnell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top