>>Aston, move your Setfocus() code from Valid() to LostFocus() and it will work.
>>
>Nick,
>
>SetFocus from a LostFocus will only work if you also include a NODEFAULT after the SetFocus call. Otherwise the dafualt behavior fo the LostFocus will move focus to the next control after your SetFocus has done what it is doing.
Hi Jim,
I know about this point and did so before, but since awhile I found that NODEFAULT is not necessary here.
If we make a simple test:
Create a form,
Drop 5 textboxes on the form.
In text4.LostFocus() put
this.parent.text2.SetFocus()
In my tests this works identically to
* text4.LostFocus()
this.parent.text1.SetFocus()
NODEFAULT
and NODEFAULT presence seems to have no effect on successful SetFocus to text2 textbox, no matter if you use Tab, Enter, clicking on another control or pressing Esc in order to leave the text4 textbox. I tested in VFP 3, 5, and 6 and it all worked the same for me. I also tried with adding the button with .Cancel = .t. and the button with .Default = .t.
The only case found when SetFocus was not set, is when you are tracing the code in the Debugger and have some code immediately
after the line
this.parent.text1.Setfocus()
myVar1 = 0
myVar2 = 1
In this case the focus goes to the next control and adding NODEFAULT also has no effect on this behaviour.
If we are not tracing the code - Setfocus() from LostFocus() works fine, and the code after SetFocus line is executed too.
So, my point is that NODEFAULT is not necessary when you are trying to SetFocus from the LostFocus() event.
I would be glad to hear your thoughts about that.
Nick
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro
"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison