samedi 14 mars 2015

Preventing Tab to switch in Winforms

I have a TabControl in my Winforms with multiple Tabs in it. The user can input some data and I want to check certain conditions if he wants to change the Tab. If a condition doesn't match, the user should stay on this Tab.


I tried something like that:



public void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
{
if (tabControl2.SelectedTab == tabPage10)
{
//check condition
if(condition)
{
tabControl2.SelectedTab = tabPage10;
}
}
}


The problem here is that when I'm on TabPage10 and select TabPage9 for example, he switches to 9 without checking. When I select TabPage10 again, he checks the conditions but I want him to check the conditions when I'm in this TabPage and want to select another TabPage. How does this work?


Aucun commentaire:

Enregistrer un commentaire