Link to home
Start Free TrialLog in
Avatar of mshire
mshireFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Control Validation & the Tab Control

Hi, I'm using VB.net and doing various validation on controls using the Validating event and setting the e.Cancel = true if the validation was unsuccessful.

This works fine on everything apart from when the user hits a tab on a tab control... its seems to fire the validating event 2/3 times but the tab still changes and an incorrect value is left stored in the control. Why should this happen, surely the tab control shouldn't receive the focus if I set e.cancel = true in the validating event...?

Any ideas?
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

This description is a little vague.


<< tab control shouldn't receive the focus if I set e.cancel = true in the validating event>>
The Validating event is when a control is about to lose focus.

The events occurs in this order:

Leave
Validating
Validated
LostFocus

So unless you are putting in e.Cancel=True in another control's Validating event, then the tab control will receive the focus.
Avatar of morphinex
morphinex

Try sticking in

e.handled = true

somewhere in the code.
Avatar of mshire

ASKER

Sorry...

I have a Textbox in which I'm doing some validation using the validating event. If the validation fails I set e.Cancel=true and the textbox does not lose the focus when clicking anywhere on the form.... except when clicking on a tab of a tab control...

Somehow the tab control seems to continue to work and switches pages, firing the validating event of the textbox a few times, but eventually losing the focus leaving an invalid value...

Does this make more sense?

Are you still having a problem with this?
Avatar of mshire

ASKER

Yes I've still got the problem.

The validating event of a textbox doesn't seem to stop the tab control changing tabs... which is very annoying, any work around would be welcomed.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Did you get that last comment?  Did you find a fix yourself?
Avatar of mshire

ASKER

Thanks for your help it would appear that it was my problem, if you place sender.focus (I don't know why this was done....) in the validating event it causes the events I described above.