×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How to select an item using more than one key press
2

How to select an item using more than one key press

How to select an item using more than one key press

(OP)
Hello dear colleagues!

I have a grid on a form, which displays all records from a file.

I just select an item (a record) of the file by key pressing the first letter of the desired item name ("PRODUTO"). It works fine. Please, see the ilustration bellow:


Now I want to make it to work better: If I want to select the item 'CHOCOLATE', instead of pressing just 'C' (it selects the first 'C' ocurrency, CAFE) and arrow down key 7 times to find the desired item, 'CHOCOLATE', I want to press the keys C and H to go directly to 'CHOCOLATE'.

Is it possible?

Thank you,
SitesMasstec

RE: How to select an item using more than one key press

What you have is not the default behaviour of a grid. You clearly have some code in the Keypress event of your grid that is letting you go to the first item by pressing the relevant letter. You will need to modify that code to get the functionality you want.

If you could post the code in question (as code, not as a screenshot), we might be able to help.

Be aware also that the listbox has this behaviour build it. It is called an incremental search. But a listbox is quite different from a grid, and you probably won't want to use a different control just to get this functionality.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: How to select an item using more than one key press

(OP)
Hello Mike!

Here is the code.

Note that Grid is populated with data from the file ITENSEST

CODE -->

Object: Form1    Procedure: KeyPress

LPARAMETERS nKeyCode, nShiftAltCtrl

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

IF ISALPHA(CHR(nKeyCode))
   SELECT ITENSEST
   LOCATE FOR UPPER(LEFT(WENOME, 1)) = UPPER(CHR(nKeyCode))
ENDIF 

----------------------------------------------------------------
----------------------------------------------------------------

Object: Grid1    Procedure: DblClick

* Codigo Escolhido

EsteCodigo=itensest.wecodi 
EstaDescri=itensest.wenome
thisform.Release

----------------------------------------------------------------

Object: Grid1    Procedure: Init

EsteCodigo=0
EstaDescri=""

---------------------------------------------------------------- 

Thank you,
SitesMasstec

RE: How to select an item using more than one key press

You were already getting advice in thread184-1777773: Highlighting a row in a Grid typing a letter

Quote (Olaf Doschke)

...have a textbox above the grid header and let the user enter the "begins with" letters there.

Then the LOCATE becomes LOCATE FOR UPPER(WENOME) = UPPER(Thisform.SearchTetbox.Value)

or you go with other recommendations of that past thread, like using the Foxy Classes Tamar mentioned there.

Or go with this┬┤┬┤; https://books.google.de/books?id=wKNfTHRNkLAC&...

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: How to select an item using more than one key press

(OP)
Hello colleagues!

Now I wrote these codes:

CODE -->

Object: Form1    Procedure: Init

EsteCodigo=0
EstaDescri=""
thisform.SearchTetbox.SetFocus

----------------------------------------------------------------
----------------------------------------------------------------

Object: Grid1    Procedure: DblClick

* Codigo Escolhido

EsteCodigo=itensest.wecodi 
EstaDescri=itensest.wenome
thisform.Release

----------------------------------------------------------------
----------------------------------------------------------------

Object: SearchTextBox    Procedure: LostFocus


SELECT ITENSEST
LOCATE FOR UPPER(WENOME) = UPPER(Thisform.SearchTetbox.Value)

EsteCodigo=itensest.wecodi 
EstaDescri=itensest.wenome
*thisform.Release

---------------------------------------------------------------- 
---------------------------------------------------------------- 

And it resulted wrong:

Thank you,
SitesMasstec

RE: How to select an item using more than one key press

What is your setting for EXACT? OFF is the default for a good reason.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: How to select an item using more than one key press

(OP)
Olaf:

I used this and the result was the same:

CODE -->

LOCATE FOR UPPER(SUBSTR(WENOME,1,LEN(Thisform.SearchTextBox.Value))) = UPPER(Thisform.SearchTextBox.Value) 

And Set Exact is set to OFF

Thank you,
SitesMasstec

RE: How to select an item using more than one key press

Di you set a max length in the SearchTextbox? Anything that pads what you enter there with spaces?

For comparisons with EXACT OFF it's most important the right hand side of a comparison is just the letters typed in, you don't need SUBSTR() and if you'd shorten the field value, then better with LEFT().

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: How to select an item using more than one key press

Besides, the WENOME field values are already all upper case, as can be seen from the grid, don't use function on fields, that just means an index on WENOME will not be used.

SELECT ITENSEST
LOCATE FOR WENOME = UPPER(ALLTRIM(Thisform.SearchTextBox.Value))

Unless you have an index on UPPER(WENOME), then you can stay with LOCATE FOR UPPER(WENOME) = UPPER(ALLTRIM(Thisform.SearchTextBox.Value)), but don't apply more complex expressions on the WENOME field, that disables the use of this index.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: How to select an item using more than one key press

(OP)

Problem solved, thank you Olaf and Mike.

Thank you,
SitesMasstec

RE: How to select an item using more than one key press

(OP)

Hello colleagues!

Now a small problem appeared: when executing the form (1), if the mouse pointer is over the 2nd column Header ("Produto") and in which area the SearchTextBox is located, the objects there become invisible (2).



If the user click over the area where the invisible SearchTextBox is, then it becomes visible again.

Is there a way to avoid this?

Thank you,
SitesMasstec

RE: How to select an item using more than one key press

I've just got back to this thread after my initial post yesterday, and I see Olaf has given you a good solution. Unfortunately, I don't know the answer to your latest problem - where the textbox becomes invisible until the user clicks on it. If you don't find a better solution, would it be an option to move the textbox completely above the grid?

But I did notice another issue. What happens if the user types a value that is not present in the table? In other words, if the LOCATE fails? As far as I can see from your code, the highlight will go the end of the table in that case, which is probably not what you want.

The solution would be to save the current record pointer immediately before the LOCATE, and then return to that record if the LOCATE fails:

CODE -->

lnSaveRec = RECNO()
LOCATE FOR ....
IF NOT FOUND()
  GO lnSaveRec
ENDIF 

Keep in mind too that after moving the highlight you might need to set focus on the grid to make the change visible.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: How to select an item using more than one key press

(OP)

Hello Mike!

I followed your 2 advices:
1) put the SearchTextBox outside the Grid
2) the record pointer does not move if an item to be searched is not found

... and it looks great now! Thank you very much.


Thank you,
SitesMasstec

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close