Just thought I would post this in case anyone else was digging around for the same issue:
When you close a tab, it does not get automatically removed from the tab collection associated with your tab control...a reference to the tab stays in your tab collection, but your controls and data may not be kept, or you may run into problems if you try to create a new tab with the same key (at least in my experience). So, the solution is simple, you just need to make sure that you remove the tab from your collections. Here is the code:
{
UltraTabsCollection tabs = MyTabControl.Tabs;
tabs.Remove(e.Tab);
}
That will get your tab out of the collection when it gets closed.
Hey one addition. I found that although the above code works pefectly in removing tabs, doing so, does not automatically re-order the tab's index. This causes a "key already in use" error when I dynamically added tabs back.
My fix is as follows:private void MyTabControl_TabClosed(object sender, TabClosedEventArgs e){
UltraTabsCollection tabs = MyTabControl.Tabs;tabs.Remove(e.Tab);
for (int i = 0; i < tabStrip.Tabs.Count; i++){ MyTabControl.Tabs[i].Key = i.ToString();}
Hopes this helps others..
Much appreciated. Thanks.