This is the same behavior as the desktop. What happens is that the
SelectedIndex is in fact getting changed as each TabPage is being removed
from the collection. If this is really messing with your application then I
guess a simple way would be to unhook from the SelectedIndexChanged event
before calling the Clear method and then hook back up when you're done. Or
you could always just use a private boolean variable as a flag to indicate,
inside your SelectedIndexChanged handler, to not process the event and
instead just exit if you are in the process of clearing the collection via
the Clear method. This doesn't really seem like an intuitive behavior to
fire the event for every page removed but even if it behaved as expected it
should still fire at least once anyways - going from the currently selected
index to "-1" - as this would definitely be a change in the selected index.
So if this type of activity would mess with your app then you should
probably handle it anyways.
--
Tim Wilson
..Net Compact Framework MVP
{cf147fdf-893d-4a88-b258-22f68a3dbc6a}
paxvista said:
I currently have some code that dynamically clears and creates tab pages
on a tab. I'm currently doing this because the hide method doesn't appear
to work on a tabpage. Maybe this will change when I add sp2 to my emulator.
But in the meantime, when I call the Clear() method on the TabPages
collection of the tab, it triggers the selected_index_changed event for each
tabpage on the page. I would consider this a bug, but maybe there is design
reason I have not considered.