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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlighting a row in a Grid typing a letter 1

Status
Not open for further replies.

SitesMasstec

Programmer
Sep 26, 2010
523
Brasil
This is a Form, with a Grid inside it that performs the selection of an item by two ways:
- double clicking on the desired item
- moving the up and down arrow keys through the items and pressing the enter key

(items are presented in alphabetical order)
Grid7_jyqtxo.jpg


The Grid has hundreds of rows (items). When I wish to select an item which begins with 'M' letter (for example, I am searching for "Mango") I navigate more fast using the up and down navigating arrows in the Form vertical bar.

Is it possible to type the M letter and the Grid just highlights on the first item ocurrence beginning with the letter M (without selecting it, because before the "Mango" item I have "Macarroni")?


Form1, KeyPress event:
Code:
LPARAMETERS nKeyCode, nShiftAltCtrl

IF nKeyCode=13 AND nShiftAltCtrl=0 
	EsteCodigo=itensest.wecodi 
	EstaDescri=itensest.wenome
	thisform.Release
ENDIF



Thank you,
SitesMasstec
 
You can trap the alphabetical key in your Keypress event, just as you are doing with the Enter key. You then locate the record in the underlying cursor that you want to highlight. Finally, set focus to the grid.

Something like this:

Code:
LPARAMETERS nKeyCode, nShiftAltCtrl

IF ISALPHA(CHR(nKeyCode))
  SELECT TheTable
  LOCATE FOR UPPER(LEFT, TheField, 1)) = UPPER(CHR(nKeyCode))
  THIS.SetFocus
ENDIF

I posted this in a hurry, so can't guarantee it is 100% correct, but it should give you the general idea.

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Well, in a Listobx you could simply set IncrementalSearch= .t.

Make it simple, for example this way

Code:
lcLastKey = UPPER(LASTKEY())
IF ISAPLPHA(lcLastkey)
   SELECT itensest
   LOCATE FOR produto = lcLastKey
ENDIF

Notice: If FOUND() becomes .F. after LOCATE, you know there is no record starting with the entered letter. Either you then return back to the RECNO you started from or the grid will show the end of the list. It won't matter much, as the next keypress can fix that. Now if you'd like incremental search, eg also be able to search AM to get to the first product starting with AM instead of M, then rather don't do such things with Keypress, have a textbox above the grid header and let the user enter the "begins with" letters there.

Bye, Olaf.
 
Hello colleagues!

I implemented Mike's code in my application and it is working fine.

Olaf, I do not have a Listbox (for letter input) in the Form, only a Grid.

Tamar, I downloaded the Foxy classes, as you advised, for future use. I have to stay in the basics of OOP in VFP for now.

Thank you all.


Thank you,
SitesMasstec
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top