C# WinForms: When I call Clear() method of a TabPages:
tabControl.TabPages.Clear();
it is also firing SelectedIndexChanged event
tabControl_SelectedIndexChanged
. But I don’t want that. Is there a formal or even a hackish way to prevent this being called when I call Clear()? I still want it to be called whenever the user clicks on a tab, but I just don’t want it to automatically get called when somewhere else I am calling the Clear() method.
Thank you.
In addition to the comment I made you could make it an Extension Method:
Now you don’t need to remember to unhook and rehook the event handler in every place you would like to clear the TabPages at. You just call:
Note:
I havn’t tried this code but it should work.