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

Autocomplete in a textbox 2

Status
Not open for further replies.

scklifasovskiy

Programmer
Nov 12, 2012
57
CA
I started using automplete functionality and everything works just fine.
Only one problem -- when you use keyboard.
Example:
I type letter P --> getting drop-down with all words starting from P --> go down to desired word -->
highlight -- NOW -->unless i press enter twice quickly -- it doesn't select and leaves P in a box... With mouse-click it works perfectly...
Is there some way i caun make it behave exactly like mouse-click?
 
I'm not seeing this behaviour.

I press P, and see the drop-down. I move the highlight (using the keyboard) to the desired entry. I press Enter (once only), and the hightlighted string appears in the main part of the textbox.

It's true that I might have to press Enter a second time in order to act on the selected entry (in my case, to activate the OK button), but that's normal behaviour for any editable control.

Can you clarify exactly what steps you need to take to produce the problem?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I do exactly what you do. But..just realized I have code in Keypress()...so each time i press Enter--it runs this code... but I was hoping it would pick-up selected from drop-down first, but when i press enter -- this code ignoring what is highlighted and read the typed value (one letter). I hope I am clear.
 
Yes, that's what I would expect.

The Keypress fires when you type a letter, and also when you move the highlight to select an entry. In that case, it will trap the down-arrow keys (ASCII 24) that you use to move the highlight, and then the Enter key (ASCII 13) when you make the selection.

Maybe you should move your code to the InteractiveChange event. That will fire each time you type a letter, and also when you hit Enter. The Value property will then always tell you the current value of the textbox, whether you typed it yourself or used Autocomplete to generate it. Is that what you want?

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
i tried moving code (iteracivechange as well)...doesn't seem to matter... When i press Enter(nkeycode=13)-- i need to execute code to search for an item... BUT if I typed "P" ..then highlighted "Peter" from dropdown and pressed Enter -- value of a textbox stays "P" ...
 
BUT if I typed "P" ..then highlighted "Peter" from dropdown and pressed Enter -- value of a textbox stays "P" ...

That's not what I'm seeing - and not what I would expect. Once you've highlighted "Peter" and pressed Enter, the textbox should contain "Peter". That's how auto-complete works.

Of course you would still need to take some futher action to execute the search - because there's no way the text box can know that you've finished entering the search term. In my case, I set the Default property of the Search button to .T., so the user only has to hit Enter again to do the search.

If your aim is to avoid that extra keystroke - well, I don't see how you can do that.

Mike





__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
in my keypress() i have a code:
if !empty(textbox.value) and keynode=13
do something
endif
when i press keynode=13(enter) -- value of textbox is "P" instead of "Peter" that i selected by Enter...
However, when box is empty and i just select from drop-down -- everything works!
Please note, that i report this problem only when using keyboard...
 
also... i don't want to fire search code when user just types(iteracive change)...only when he pressed enter i want to start searching..but as i said -- if i type "P" then select "Peter" from dropdown by keyboard then press enter-- in KeyPress() value of textbox is still "P"...
 
The "do something" part would be interesting. The keypress obviously is running earlier and suppresses the normal behaviour. Acting on a keypress isn't a good solution for that matter. Stop it. Remove the code from the Keypress, it's the trouble maker.

SET EVENTTRACKING ON and see what happens in which order, and then you'll know.

Bye, Olaf.
 
Deos it really make sense to start the search as soon as the user presses Enter? What if they want to edit the item they have selected? For example, they might select "Peter", but want to change it to "Petra". Or to "Peterloo".

I would suggest that you remove the code from the Keypress event. Let them use auto-complete in the way that it is intended, and then hit Enter again (or click a Search button) when they are ready to search.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I did EVENTTRACKING, and keypress runs before interactive. That means the text isn't in the textbox.value when you start searching. And if you move focus to grid or something like that, that may even cause the autocomplete not to finsh.

Both me and Mike agree the code in Keypress is not good. If you want a selection from the dropdown list to be the final search then the Valid() event would be the right place for your search.

I'd also suggest a seperate search button. That way you can add further search entry textboxes for searching several terms in several fields and make it a more specialised search form.

Bye, Olaf.
 
Guys!
I took your suggestions...moved code from KeyPress() to Valid().. modified it slightly .. and Voila!
Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top