I have a TabControl form. I need to make sure users have saved the data before changing tab or closing the form.
Whenever they try to close the form or change tab they get a "Save changes?" YesNoCancel message box.
Yes = save and close (or change tab)
No = don't save and close(or change tab)
Cancel = don't save and don't close (or change tab), leave it be
Yes and No options are no problem at all. My problem is with the Cancel option.
When user tries to close a form I use the following code in form_closing event and it works perfectly:
If msgResult = MsgBoxResult.Cancel Then
e.Cancel = True
But when user tries to change tabs, I cannot stop the SelectedIndexChanged event. It happens regardless.
How can I stop this event and stay on the tab? I could change the selectedIndex back to the original tab but that would remove the changes user have made. I simply want to intercept the SelectedIndexChanged event and close the message box.
Your help would be appreciated.