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

Incremental Search - Like Help Index

ListBox

Incremental Search - Like Help Index

by  craigsboyd  Posted    (Edited  )
Slighthaze = [color blue]NULL[/color]
[img http://www.sweetpotatosoftware.com/ttimages/listsearch.gif]
It works good in help so why not give your users the same ability for your application? NOTE: There is a small delay when running it since the list of entries is being created randomly. (Cut-n-paste the code below into a prg file and run it from within VFP)

PUBLIC oForm

oForm = CREATEOBJECT("clssearch")
oForm.visible = .t.

DEFINE CLASS clssearch AS form

Top = 1
Left = 0
Height = 473
Width = 287
DoCreate = .T.
Caption = "Incremental Search"
WindowState = 0
Name = "clssearch"

ADD OBJECT list1 AS listbox WITH ;
Height = 408, ;
Left = 12, ;
Sorted = .T., ;
Top = 48, ;
Width = 264, ;
Name = "List1"

ADD OBJECT text1 AS textbox WITH ;
Format = "!K", ;
Height = 23, ;
Left = 12, ;
Top = 12, ;
Width = 264, ;
Name = "Text1"
Format = "!K"

PROCEDURE Init
LOCAL nCount, nCount2, nWordLength, sItem, nUpper, nLower
nUpper = 90 &&ASCII
nLower = 65 &&ASCII
FOR nCount = 1 to 250
sItem = ""
nWordLength = INT((35) * RAND( ) + 1)
FOR nCount2 = 1 TO nWordLength
sItem = sItem + CHR(INT((nUpper - nLower + 1) * RAND( ) + nLower))
ENDFOR
thisform.List1.additem(sItem)
NEXT
ENDPROC

PROCEDURE Activate
thisform.text1.setfocus()
endproc

PROCEDURE list1.interactivechange
thisform.text1.value = this.value
thisform.text1.refresh()
ENDPROC

PROCEDURE text1.interactivechange
LOCAL nCnt, sSearchFor, nLen
sSearchFor = ALLTRIM(this.value)
nLen = LEN(sSearchFor)
FOR nCnt = 1 TO ThisForm.List1.ListCount
IF sSearchFor == LEFT(ALLTRIM(ThisForm.List1.List(nCnt)),nLen)
thisform.List1.Selected(nCnt) = .t.
thisform.List1.refresh()
EXIT &&Found one
endif
ENDFOR
ENDPROC

ENDDEFINE
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top