views:

138

answers:

1

I'm doing things as said in How do I prevent the user from changing the selected tab page in a TabControl?

Things are working fine. But the validating event of tabpage1 occurs if I've tabpage1 is currently selected and user clicks on tabpage1 itself. and later when user clicks on tabpage2 validating event for tabpage1 doesn't fire.

What happens is if I do e.Cancel in validating event of tabpage1, in the above case, when user clicks on tabpage1 by mistake having tabpage1 already selected, it will prompt user that "Do you want to stay on current tab to save data or move from the current tab?". and if user clicks Stay but doesn't do any changes. And then when he correctly clicks tabpage2, Validating event of tabpage1 is not firing.

I've uploaded the sample application here. You can run and see the behavior to properly understand the problem

+1  A: 

Use TabControl.Selecting Event instead.

Use it like this:

tabControl1.Selecting += tabControl1_Selecting;

private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
{
    e.Cancel = !(can switch tab);
}
Jens Granlund
Thanks for the link. I will be using Deselecting event.
Ismail