TabPage issue

K

Ken

I have a custom TabPage class the I add to a standard TabControl. I have a
NumericUpDown control on the TabPage whose Validating event is tied to a
method in the TabPage class. If the user types in a value, does not use the
up/down arrows to change the value, I validate the Text property in the
Validating event. If it is not valid I display a MessageBox then set the
cancel property of the CancelEventArgs to true, then call the NumericUpDown
control Focus method, then select the text of the NumericUpDown control.
This all works great if the user uses the Tab key to move to the next
control, or clicks another control on the current TabPage.

The problem arises when the user after typing in what is an invalid value
into the NumericUpDown control then clicks another Tab in the TabControl.
Here is what happens.

1. Enter invalid data on the current TabPage
2. Click another TabPage on the TabControl
3. The MessageBox is displayed twice with the originating TabPage visible.
4. The TabControl switches to the TabPage that was clicked
5. The MessageBox is displayed again. (Third time)
6. Anything after this causes the MessageBox to display and I can not leave
the TabPage that was clicked.

Can any one provide any ideas as to what is happening?

Thank You

Ken
 
Y

Ying-Shen Yu[MSFT]

Hi Ken,

You not set focus in Validating event handler, the docs listed the order
that windowsforms do validation,
1.Enter
2.GotFocus
3.Leave
4.Validating
5.Validated
6.LostFocus

Setting focus in Validating event will reenter into the first step, which
will cause some problem.

To keep the execution in order , you may try it in this way.

delegate bool BooleanMethodInvoker();

private void tabPage1_Validating(object sender,
System.ComponentModel.CancelEventArgs e)
{
if (numericUpDown1.Value < 6)
{
MessageBox.Show("sdfsfsa");
e.Cancel = true;
BeginInvoke(new BooleanMethodInvoker(numericUpDown1.Focus));
}
}

Does it solve your problem?
If you still have problem on that , please be free to reply this thread to
let us know.
Thanks!


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, "online" should be removed before
sending.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top