Hi Dennis,
Based on my understanding, you want to validating all the controls on the
tabpage before switch pages.
I think you should hook the Validating event for all the controls on your
form. For certain control, once it has focus, it will validate its data for
closing, leaving, etc.. events.
So the only problem when changing pages is when all the child controls on
the form have no focus, then swith pages will not trigger the child
controls' validating events.
For this issue, I think there are 2 workarounds:
1. loop all the controls on the tabpage, then judge if each control is the
default value(We suspect the default value is not the valid value), if it
is the default value, does not allow the index change.
2. You may add a custom validating type event for each tabpage, then when
registering event handler for child control's Validating event, you should
also register it for the tabpage custom event, then in
TabControl.SelectedIndexChanged event, you can explicit invoke all the
validating event handler, if not valid, then swith back to the orignal
tabpage.
To swith back to the original tabpage, you may use a variable to store the
original page index. Do like this:
int orginal_index=0;
private void tabControl1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
Console.WriteLine(this.tabControl1.SelectedIndex.ToString());
if(this.b_switch==true)
{
this.tabControl1.SelectedIndex=orginal_index;
}
orginal_index=this.tabControl1.SelectedIndex;
}
bool b_switch=false;
private void button1_Click(object sender, System.EventArgs e)
{
if(b_switch==true)
{
b_switch=false;
}
else
{
b_switch=true;
}
}
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.