I have a textbox at the top of a form and a grid below. I want to stay in the
textbox and enter data - hit return and update the grid - and then go right
back to the textbox. Don't want to leave it until I click out of it.

I use valid to test the data in the textbox and return(.t) just after
updating the grid. If not valid I return .f. and tell the user and the focus
stays in the textbox. I want it to stay there even if I return .t.

Return .t causes focus to go to the next object. I don't want that. When the
user is done entering data and updating the grid data then they can click out
of the textbox.

Using VFP 9. XP Pro.

Any Ideas would be very appreciated.

TIA

Re: Keeping Focus in a TextBox by Fred

Fred
Mon Aug 07 23:10:14 CDT 2006

In the LostFocus(), do a NODEFAULT. You can optionaly return .t. or .f.,
depending on your needs.

--
Fred
Microsoft Visual FoxPro MVP


"Phrank" <Phrank@discussions.microsoft.com> wrote in message
news:9A0B5685-E29B-4464-AF45-90C0289D64E0@microsoft.com...
>I have a textbox at the top of a form and a grid below. I want to stay in
>the
> textbox and enter data - hit return and update the grid - and then go
> right
> back to the textbox. Don't want to leave it until I click out of it.
>
> I use valid to test the data in the textbox and return(.t) just after
> updating the grid. If not valid I return .f. and tell the user and the
> focus
> stays in the textbox. I want it to stay there even if I return .t.
>
> Return .t causes focus to go to the next object. I don't want that. When
> the
> user is done entering data and updating the grid data then they can click
> out
> of the textbox.
>
> Using VFP 9. XP Pro.
>
> Any Ideas would be very appreciated.
>
> TIA
>



Re: Keeping Focus in a TextBox by Mike

Mike
Tue Aug 08 03:29:24 CDT 2006

On Mon, 7 Aug 2006 19:16:01 -0700, Phrank
<Phrank@discussions.microsoft.com> wrote:

>I have a textbox at the top of a form and a grid below. I want to stay in the
>textbox and enter data - hit return and update the grid - and then go right
>back to the textbox. Don't want to leave it until I click out of it.
>
>I use valid to test the data in the textbox and return(.t) just after
>updating the grid. If not valid I return .f. and tell the user and the focus
>stays in the textbox. I want it to stay there even if I return .t.
>
>Return .t causes focus to go to the next object. I don't want that. When the
>user is done entering data and updating the grid data then they can click out
>of the textbox.
>
>Using VFP 9. XP Pro.
>
>Any Ideas would be very appreciated.
>
>TIA
You can use a numeric argument instead of logical with Return from the
Valid. The numeric argument shifts the focus back (-ve argument) or
forward in the Tab order to whatever control you want. Sounds like you
should try Return -1 or 0.

Mike.

Re: Keeping Focus in a TextBox by Jim

Jim
Tue Aug 08 06:37:52 CDT 2006

I usually use the lostfocus event and set focus back to the same object
in these situations. You cannot do the checking in a valid because it
does not allow a setfocus command. This approach is also needed if you
want to make a container behave like it is modal.
You will also need a way to verify that the user actually wanted to
leave the object.
If it applies in your case, assume that an enter or tab meant data was
entered and you want to stay in the text box. any other event allows
focus to leave.

in lostfocus.
if lastkey = enter or tab then
this.setfocus
endif


Re: Keeping Focus in a TextBox by Phrank

Phrank
Tue Aug 08 10:32:02 CDT 2006

Thanks All. I cannot return .f. in valid because it puts a "Invalid input" on
the screen. What I have is a bar code scanner that enters data into a textbox
and when the return key is seen I update a grid below on the form. I want to
stay in the barocde text field until the user is done and moves the mouse to
the Done button.

Thank You Jim. I am using LostFocus. Am looking for the return key and can
see it and then do the processing. Still it goes to the next field on the
form even tho I do a setfocus back to the barcode input text field.

Here is some code from the LostFocus event. Maybe someone can see what I
cannot. Thanks.

-------------------------------------------------------------------------------------
IF EMPTY(This.Value) then
RETURN(.t.)
ENDIF
ThisForm.Barcodex1.SetFocus
IF LASTKEY() = 13 then
SELECT tools
SET ORDER TO OURNUMBER && OURNUMBER
SEEK ALLTRIM(UPPER(ThisForm.Barcodex1.value))
IF FOUND() then
IF !EMPTY(ThisForm.tbBJobno.Value) THEN
IF RLOCK() then
*=MESSAGEBOX("Record Locked")
ThisForm._GRID1.column1.Text1.Value = .t.
ThisForm._GRID1.column6.Text1.Value = ThisForm.DATEINX.Value
ThisForm.Barcodex1.Value = ""
PickedJob = ThisForm.tbBJobno.Value
? CHR(7)
*this.setfocus
ThisForm.Barcodex1.SetFocus
return(.f.)
ThisForm.Refresh
ENDIF
ELSE
=MESSAGEBOX("Please enter a Jobnumber above first.")
This.Value = ""
ThisForm.Refresh
return(.f.)
ENDIF
ThisForm.Refresh
ELSE
MESSAGEBOX("Not Found")
ThisForm.Refresh
RETURN(.f.)
GO top
ENDIF
ENDIF
SET ORDER TO TOOLTYPE && TOOLTYPE
ThisForm.Barcodex1.SetFocus
ThisForm.Refresh
--------------------------------------------------------------------------------------

"Jim Czeb" wrote:

> I usually use the lostfocus event and set focus back to the same object
> in these situations. You cannot do the checking in a valid because it
> does not allow a setfocus command. This approach is also needed if you
> want to make a container behave like it is modal.
> You will also need a way to verify that the user actually wanted to
> leave the object.
> If it applies in your case, assume that an enter or tab meant data was
> entered and you want to stay in the text box. any other event allows
> focus to leave.
>
> in lostfocus.
> if lastkey = enter or tab then
> this.setfocus
> endif
>
>

Re: Keeping Focus in a TextBox by Bernhard

Bernhard
Tue Aug 08 13:12:20 CDT 2006

Hi Phrank,

maybe try this in VALID of your barcode-textbox:

IF !mdown()
RETURN 0
ENDIF

This should keep the focus in the textbox without an error message, but only if
you try to leave the textbox with the keyboard. If you try to leave with the
mouse, this should be possible.

Regards
Bernhard Sander

RE: Keeping Focus in a TextBox by Yan

Yan
Tue Aug 08 19:55:06 CDT 2006

Hi Phrank,

Try to set the TabStop property to FALSE (.f.) of all the objects except the
TextBox that accepts the data entry, and you may also set the SelectOnEntry
property to TRUE (.t.) to that TextBox to automatically delete its value
everytime a new set of data entry will be done.

Hope this would help you.


Ryan Paradela



"Phrank" wrote:

> I have a textbox at the top of a form and a grid below. I want to stay in the
> textbox and enter data - hit return and update the grid - and then go right
> back to the textbox. Don't want to leave it until I click out of it.
>
> I use valid to test the data in the textbox and return(.t) just after
> updating the grid. If not valid I return .f. and tell the user and the focus
> stays in the textbox. I want it to stay there even if I return .t.
>
> Return .t causes focus to go to the next object. I don't want that. When the
> user is done entering data and updating the grid data then they can click out
> of the textbox.
>
> Using VFP 9. XP Pro.
>
> Any Ideas would be very appreciated.
>
> TIA
>