I am handling tab change in the WinForms TabControl’s Deselecting event. However, in some cases I am deleting the tab that I clicked on before I switch to it.
scenario
I have tab 1 and tab 2
currently I’m in tab 1
I click on tab 2
tab 1 Deselecting Event Removes Tab 2 from the tab collection
Crashes at OnPaint because it’s trying to go to a tab that no longer exists. (ArgumentOutOfRangeException). It crashes before it hits the Selecting Event.
I don’t want to see if the tabcount changed in deselecting because I only want to cancel if the tab I’m going to no longer exists.
Any help would be greatly appreciated.
private void TabControl_Deselecting( object sender, TabControlCancelEventArgs ) {
DoSomeWork();
}
Assume that DoSomeWork deletes the Tab I clicked on. How can I find out if it did delete the tab I was intending to go to?
No repro. The scenario is strange but I can’t get it to crash. Do make sure you cancel the Deselect.