Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fun with focus

Status
Not open for further replies.

bedrock

Programmer
Nov 6, 2002
94
US
in some ways this continues thread1254-839231. go skim that over, then head back to this thread.

the thread above addresses the problem of when to run code from Valid. ive implemented some ideas from there, but i still have some issues to deal with.

my form has 2 buttons (save and discard), a textbox for entering data, and a grid. once data is entered into the textbox, i update the grid (increment the count on the row containing the item in the textbox).

i need focus to return to the textbox after that happens, reason being the users will enter data w/ a barcode scanner, so i dont want them to have to click it each time. but they also need to be able to click the grid and enter in values manually, along with being able to click the buttons. since When and GotFocus fire before Click, i havent been able to find a way to allow the user to do this.

the closest ive gotten is to set a form property when the form is clicked, and check for that in the Grid's When event. but the user has to click twice, once to set the var and then again to select a control.

so, foxpro gurus, have any suggestions?

what we see depends mainly on what we look for.
--John Lubbock
 
I'm not sure I understand your question correctly, but if all you want to do is set focus to the textbox after the button is clicked then add this code at the end of the click event for the button:

ThisForm.myTxtBox.SetFocus() &&myTxtBox = your textbox name
NODEFAULT

Let me know if I am missing something here.

-Kevin
 
My appologies. Let me try and explain better...

Focus begins on the textbox. When a user scans a barcode, focus automatically transfers to another control. I want the focus to go back to the textbox once this happens, so that another barcode can be scanned without clicking in the textbox.

The places of re-setting focus i found were in the valid, lostfocus of the textbox, and when, gotfocus of the other controls.

Thus the problem lies in when someone tries to click on a different control, such as manually changing the grid, or clicking one of the buttons. before the click event fires, the valid,lostfocus,when,gotfocus all fire first. so focus will never leave the textbox.

I'm no fp guru, I've only been using it a couple of weeks. But from what I can see there is no way to get around this. So I posted here wondering if any of the experts had a trick up your sleeve.

Currently I'm heading down a different road, more design rather than programming tricks. I'm currently working on setting up a 'scan' mode and 'manual' mode, and intercept keystrokes in the form's keypress event to switch them.

what we see depends mainly on what we look for.
--John Lubbock
 
Dave:
Thanks for your suggestion about SET CONFIRM ON.

However, I made it work with just a couple of lines. Once I started using my brain, I realised that the scanner appends two newline characters, and the textbox loses focus as it would from an 'Enter' keystroke. So I just have a simple KeyPress event:

Code:
LPARAMETERS nKeyCode, nShiftAltCtrl

IF nKeyCode = 13 && 'Enter'
	thisform.updategrid()
	this.Value = ""
	NODEFAULT
ENDIF

Regardless, thank you both for your help!

what we see depends mainly on what we look for.
--John Lubbock
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top