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!

Interactive Search / Autocomplete in a Text Box

Tips & Tricks

Interactive Search / Autocomplete in a Text Box

by  Imaginecorp  Posted    (Edited  )
This is an Oldie:

Code:
****** VFP9 with SP 1
Public oform1

oform1=Newobject("form1")
oform1.Show
Return


**************************************************
*-- Form:         form1 (\imaginecorp\form11.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   02/02/07 01:25:12 AM
*
Define Class form1 As Form


    Top = 3
    Left = 48
    Height = 100
    Width = 375
    DoCreate = .T.
    ShowTips = .T.
    Caption = "Auto Complete"
    Name = "Form1"


    Add Object command1 As CommandButton With ;
        Top = 67, ;
        Left = 278, ;
        Height = 27, ;
        Width = 84, ;
        Caption = "Close", ;
        TabIndex = 2, ;
        Name = "Command1"


    Add Object label1 As Label With ;
        AutoSize = .T., ;
        Caption = "Company", ;
        Height = 17, ;
        Left = 60, ;
        Top = 25, ;
        Width = 55, ;
        TabIndex = 3, ;
        Name = "Label1"


    Add Object text1 As TextBox With ;
        Format = "K", ;
        Height = 23, ;
        Left = 120, ;
        SelectOnEntry = .T., ;
        TabIndex = 1, ;
        Top = 20, ;
        Width = 207, ;
        Name = "Text1"


    Procedure Load
        If Used("customer")
            Use In customer
        Endif
        **** Do not need to do this if there is an Index
        Set Exclusive On
        ************************************************
        Select 0
        Use Home()+"samples\data\customer.dbf"
        ************************************************
        Index On company Tag company
        Set Order To Tag company
        ************************************************
    Endproc


    Procedure command1.Click
        Thisform.Release
    Endproc


    Procedure text1.InteractiveChange
        With This
            If (Lastkey() >= 32 And Lastkey() <= 127)
                .nIDSelStart = Icase(.nIDSelStart >= 0 And Lastkey() = 127,.nIDSelStart - 1,;
                    .nIDSelStart < 0,0,;
                    .nIDSelStart + 1)
                Select customer
                coldtag = Tag()
                Set Order To Tag company
                Locate For Substr(Alltrim(Upper(customer.company)),1,.nIDSelStart) = ;
                    Upper(Substr(This.Value,1,.nIDSelStart))
                ***** Could use a SEEK() as well
                If  Found()
                    This.Value = customer.company
                Else
                    If !Empty(This.Value)
                        .nIDSelStart = This.SelStart
                    Else
                        .nIDSelStart = 0
                    Endif
                Endif
                This.SelStart = .nIDSelStart
                Set Order To Tag (coldtag)
            Endif
        Endwith
        This.SelLength = Iif(!Empty(This.Value),(Len(Alltrim(This.Value))-(This.nIDSelStart)),1)
    Endproc


    Procedure text1.Init
        If !Pemstatus(This,"nIDSelStart",5)
            This.AddProperty("nIDSelStart",0)
        Endif
    Endproc


Enddefine
*
*-- EndDefine: form1
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