Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Set Focus problem
Message
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00569234
Message ID:
00569955
Views:
36
As always, Craig, you are a wonderful source of ideas and information.

Okay, I was able to do this: I created a simple form, and I put a couple of text boxes, a command button, and a customer property called lPicking which defaults to .f.

In the text box I want to validate, I added the following code to the lostfocus event:
IF !thisform.lPicking
  select customer
  seek(this.value)
  if !found()
    wait window "bad data"
    nodefault
  endif
endif  
Then, in the when event of the command button I have the following code:
thisform.lPicking = .t.
The commandbutton click then picks a value, sets it in the field, resets lPicking to .f., and returns focus to the text box.

This works because of the order events fire, even if the select box is next in the tab order.

If you "tab" out of the field, events fire as follows:
text1.validate
text1.lostfocus
command1.when
command1.gotfocus
If you click on the pick button, events fire as follows:
text1.validate
command1.when
text1.lostfocus
command1.gotfocus
Obviously, if you click on the other textbox, the text1 methods fire, but command1 doesn't because it isn't going to get focus, so you get the bad data error and that scenario works as well.

This seems to accomplish what I want to accomplish, but it requires me to do validation in the lostfocus instead of the valid event of text1. I would prefer to be able to validate in the validate method. Is that possible? Am I still missing something here?

As a general rant, one of the things that I have found frustrating that my old-fashioned boss find extremely frustrating is that VFP seems to handle all events in a vacuum. Windows obviously knows what events are pending and what happened to cause an event (such as a lostfocus or valid) to fire, because it is going to proceed to fire the appropriate subsequent events. The VFP environment (and therefore programmer/program) has no idea whatsoever. It would be oh so very nice if I could, in my validate event, execute a sys() command or some such thing and say, "oh, I guess the user hit the picklist button, so I can go ahead and skip the validation...". I find that most of the time the development tools save I loose back trying to fight my way through events to make things run smoothly for my user.

Okay, I'm done.

Oh, and thanks again, Craig, for your continued help over the years!

>This is similar to the user cancelling out entirely from the changes. Generally you'll have something like:
>
>IF LASTKEY() = 27
> RETURN .T.
>ELSE
> * Do validation
>ENDIF
>
>You could do something similar. Add a property to the form or the control, depending on where it makes the most sense, that you're doing a picklist form. When the picklist form closes, set the property back. So, the validation code would be something like:
>
>IF LASTKEY() = 27 OR This.lPickList
> RETURN .T.
>ELSE
> * Do validation
>ENDIF
>
>
>>Hi Craig!
>>
>>This question made me think of a similar question I am constantly struggling with. I think I've asked it one way or the other a dozen times, but maybe you have a suggestion.
>>
>>What about the situation where you want to know why the user is exiting the field before you decide whether or not to prevent them? For example, we have a custom lookup class that utilizes a grid. If the user keys in an invalid entry, and then decides he needs to use the lookup to get the valid entry, we have to do one of two things. We either clear the invalid value with every validation failure, or we have to put the data field and the button launching the lookup in a container together and run the validation in the lostfocus of the container. (I think that works).
>>
>>Do you have a suggestion for a better way of doing this?
>>
>>As always, thanks for your help!
>>
>>>Is there a reason you aren't using the Valid method to do the validation. Returning a 0 or .F. there will keep focus on the control.
>>>
>>>>Hi. VFP6 user here. I am having trouble placing the user back in the current field when my data validation fails. Fox doesn't like SetFocus in the valid, and it doesn't seem to work for me in the LostFocus.
>>>>
>>>>For Example (in LostFocus)
>>>>IF ! "Dr" $ This.Value
>>>> =messagebox('This list should be Doctors only.',16,'Go Back')
>>>> This.SetFocus
>>>>ENDIF
>>>>
>>>>...doesn't work
>>>>
>>>>Thanks, Randy
Paul R. Moon
Business Software Solutions
paul@businessoftware.com
Previous
Reply
Map
View

Click here to load this message in the networking platform