how to cancel a tab page change
-
How to cancel a tabcontrol selectedindex event? I can't find a proper event to do this. in 2.0 framework, some events were added: Deselected : Occurs when a tab is deselected. Deselecting : Occurs before a tab is deselected, enabling a handler to cancel the tab change. but how is it possible in .net < 2.0 :confused: thanks in advance, Niko
-
How to cancel a tabcontrol selectedindex event? I can't find a proper event to do this. in 2.0 framework, some events were added: Deselected : Occurs when a tab is deselected. Deselecting : Occurs before a tab is deselected, enabling a handler to cancel the tab change. but how is it possible in .net < 2.0 :confused: thanks in advance, Niko
You could hack the change by creating your own derived class from
TabControl
and just monitor theSelectedIndexChanged
event. The following code will prevent a user from selecting the third tab in theMyTabControl
class.using System;
using System.Windows.Forms;namespace WindowsApplication1
{
public class MyTabControl : TabControl
{
private int lastSelectedIndex = 0;
public MyTabControl() : base()
{
lastSelectedIndex = this.SelectedIndex;
this.SelectedIndexChanged +=
new EventHandler( SelectedIndexChanged );
}private void SelectedIndexChanged( object sender, EventArgs e ) { // Prevent someone from choosing TabPage number 3. if( this.SelectedIndex == 2 ) { this.SelectedIndex = lastSelectedIndex; } else { lastSelectedIndex = this.SelectedIndex; } }
}
}"we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty