Mike Yearwood
Toronto, Ontario, Canada
General information
Category:
Coding, syntax & commands
Hi Mike
Do you realize this code fires every time the user presses any key? As records are added, its gonna get slower and slower.
I rarely only have one column, so I have a button for the user to click to begin the search. The button's click would be a simple way to get around SetFocus not being possible from a textbox's valid.
You might try moving the code to the pattern textbox's .LostFocus().
If the pattern is found
RETURN .T.
else
RETURN .F.
endif
That assumes the taborder has the cursor moving from the pattern to the grid.
Is there an index tag on upper(teacher)? Have you SET ORDER TO that index? If so, you could use SEEK instead of the first LOCATE.
UPPER(TRIM(MEM1)) is being checked on every record with the LOCATEs. So, create a MEM2 like this...
SET EXACT OFF
MEM2 = UPPER(TRIM(MEM1))
IF SEEK(MEM2)
RETURN .T.
ENDIF
LOCATE FOR MEM2 $ UPPER(TEACHER)
IF FOUND()
RETURN .T.
ENDIF
WAIT WINDOW "Name not found"
GO TOP
THISFORM.GRDHILIT1.SETFOCUS()
>I am attempting the create a "pattern" section in a search box above a grid.
>
>The grid has one column with a list of names.
>
>The pattern field asks the user to enter a few characters of the person's name then press ENTER. MEM1 is the name of the variable in the pattern field.
>
>The key press code for the pattern field is below:
>
>IF NKEYCODE = 13 && enter
> SET EXACT OFF
> LOCATE FOR UPPER(TEACHER) = UPPER(TRIM(MEM1))
> IF FOUND()
> THISFORM.GRDHILIT1.SETFOCUS()
> ELSE
> LOCATE FOR UPPER(TRIM(MEM1)) $ UPPER(TEACHER)
> IF FOUND()
> THISFORM.GRDHILIT1.SETFOCUS()
> ELSE
> WAIT WINDOW "Name not found"
> GO TOP
> THISFORM.GRDHILIT1.SETFOCUS()
> ENDIF
> ENDIF
>ENDIF
>
>This code provides a momentary focus on the Grid then it returns back to the pattern box.
>
>How do I get the focus to stay on the Grid?
>
>Mike Smith
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only