In my application, I am using several tabcontrols. Some of the tabpages are created during runtime, and I keep a list of these for the purpose of going back and deleting those tabpages. The code I use for this is:
This works in most cases, but there is one tabcontrol that I'm creating dynamic tabpages on that also has several static tabpages. Whenever this subroutine runs, it removes the dynamic tabpages, but it also removes the very last static tabpage in the TC. Multiple executions of the subroutine in the same instance will eventually leave me with no static tabpages. I have done some debugging and watched the DynTPList to make sure that the names of the static pages never appear. They don't.
I am at a loss as to why this is happening. I even have other tabcontrols with mixed static/dynamic pages that this doesn't happen on. They are handled the exact same way.
Any ideas?
Edit: Resolved - I tried switching the logic around so that it loops through the tabpages instead of the list, and it appears to be working properly now. Modified code is:
VB.NET:
For Each cntrl As Control In root.Controls
clearcontrols(cntrl, ClearLists, ClearTabPages)
.
.
.
If TypeOf cntrl Is TabControl And ClearTabPages = True Then
For Each tp As String In DynTPList
If CType(cntrl, TabControl).TabPages.ContainsKey(tp) Then
CType(cntrl, TabControl).TabPages.RemoveByKey(tp)
End If
Next
End If
Next
This works in most cases, but there is one tabcontrol that I'm creating dynamic tabpages on that also has several static tabpages. Whenever this subroutine runs, it removes the dynamic tabpages, but it also removes the very last static tabpage in the TC. Multiple executions of the subroutine in the same instance will eventually leave me with no static tabpages. I have done some debugging and watched the DynTPList to make sure that the names of the static pages never appear. They don't.
I am at a loss as to why this is happening. I even have other tabcontrols with mixed static/dynamic pages that this doesn't happen on. They are handled the exact same way.
Any ideas?
Edit: Resolved - I tried switching the logic around so that it loops through the tabpages instead of the list, and it appears to be working properly now. Modified code is:
VB.NET:
For Each cntrl As Control In root.Controls
clearcontrols(cntrl, ClearLists, ClearTabPages)
.
.
.
If TypeOf cntrl Is TabControl And ClearTabPages = True Then
For Each tp As TabPage In CType(cntrl, TabControl).TabPages
If DynTPList.Contains(tp.Name) Then
CType(cntrl, TabControl).TabPages.Remove(tp)
End If
Next
End If
Next
Last edited: