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

Microsoft: FoxPro FAQ

Combo Box

How to create a "auto-fill" style combobox AND allows to add value not found by Mike Gagnon
Posted: 16 Apr 02 (Edited 7 Jul 03)

Create a combobox class and add the following:

In the InterActive Event of the ComboBox:

LOCAL lnStyle, lnLastKey, lcDisplayValue
lnStyle = this.style
IF this.style = 2
    this.style = 0
IF (lnLastKey>=32 and lnLastKey<=126)
    IF this.selstart>=1
    IF empty(lcDisplayValue)
    FOR i = 1 to this.listcount
            If Upper(lcDisplayValue) == Upper(Substr(This.List(i),1,Len(lcDisplayValue)))
                This.SelLength=Iif(nlLength <0,0,nlLength)
                this.lastdisplayvalue = this.displayvalue
                this.lastselstart = this.selstart
                this.lastsellength = this.sellength

In the combobox requery:

this.Value = this.DisplayValue && Just to reset the display value

In the valid of the combobox:

If !Empty(This.DisplayValue)
    Local cTableName,cFieldName,nAnswer,cValue
    Store Juststem(This.RowSource) To cTableName &&Won't work for VFP5.0
    Store Justext(This.RowSource) To cFieldName && This is normally used for 3 character extension, but it works for any lenght. Won't work for VFP5.0
    Select (cTableName)
    Locate For &cFieldName = This.DisplayValue
    If !Found()
        nAnswer = Messagebox("This value was not found in the table,"+Chr(13)+"Do you want to save it in the table?",36,"")
        If nAnswer = 6
            Insert Into &cTableName (&cFieldName) Values (This.DisplayValue)
            If CursorGetProp("Buffering") > 1  && Check to see if we should use tableupdate
        this.Requery() && To reset the display value
            Store '' To This.DisplayValue

Note: Properties to be created in the comboxbox class.

1. acstyle (Default value = 2)
2. lastdisplayvalue  (Default value = [none])
3. lastsellength (Default value = 0)
4. lastselstart (Default value = 0)

Mike Gagnon
Note : this code was also modified to accomodate spaces in a name.
 Thanks to viettla

Back to Microsoft: FoxPro FAQ Index
Back to Microsoft: FoxPro Forum

My Archive

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