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

'set near on' equivalent for listbox

Status
Not open for further replies.

arielap

Technical User
Aug 2, 2003
71
GB
I need the equivalent of 'set near on' for a listbox using incremental search (VFP7).
I.e. for a list of several hundred names, if the user types S and there are no names beginning with S the highlight should move to the nearest name, instead of staying in its existing position as it now does.
I've tried various bits of code comparing keystroke with list.value in InteractiveChange & Keypress , with no joy and would be grateful for any help
 
Why are you using listbox for several hundred records?
I suggest using grid instead.
 
I would suggest looking at one of the member's sites, he has a great little utility for textboxes that may be adaptable for lists.

Geoff Franklin's site is
You are right on the edge of usabiltiy with that many records, and skoko was correct that a grid may be better.

1001 Things about Foxpro has a grid class with this topic covered as well.
 
Thanks - will follow up both.

There are several 'picklists' in this app (which is a port from FP 2.6 DOS ) & I'm using Jkey with the 500-5000 record tables ones but thought listboxes would be simpler for the smaller ones whose sources are all SQLselects.
 
The way I have dealt with picklists (in a combo-box, but it should work with a listbox as well) is to have the listbox controlsource to be a cursor created from the table by a SQL select.

There is an initial selection method. Then, as the user types characters, the KeyPress event invokes an assign method, which runs a sql query to repopulate the cursor for wherever it finds a match anywhere in the cursor field.

I use this on table of over 100 records with no problems at all.


Hope that helps,

Stewart
PS If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thanks Stewart, but sources are SQL select. Incremental selection works perfectly if the typed character corresponds to an item in the list.

The problem arises when there is no item matching the key typed in by the user (the section of alphabet that would have included it being out of the user's sight). The highlight bar fails to move off wherever the previous successful 'seek' left it.

I've tried a variety of things in the Keypress, but short of repeatedly re-seeking the cursor for the next alpha character & requerying / resetting listitemid (which seems very clumsy) nothing so far has worked.

Geoff Franklin's method seems the most hopeful so far
 
Problem now solved exactly as wanted, thanks to a post by Andy Kramek in a Compuserve Fox forum a year or two back.

Solution was to set the listbox control source to the cursor's index key. Then doing a seek on the 'failed' keystroke value+1 and refresh duly places the highlight bar on the first name starting with the next alpha order character.

Thanks to all who replied to the original query
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top