Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Mike Gagnon
  Where is Mike Gagnon?
 Pointe Claire
 Canada
 Mike Gagnon
 To: Jhon Thomas
  Where is Jhon Thomas?
 
 Brazil
 Jhon Thomas
 Tags
Subject: RE: BASIC QUESTION - NEW ITEM IN A COMBOBOX
Thread ID: 311115 Message ID: 311116 # Views: 54 # Ratings: 0
Version: Visual FoxPro 9 Category: General VFP Topics
Date: Tuesday, June 28, 2011 10:48:52 PM         
   


> I KNOW it is a basic question but i am new at V Fox Pro.
>
> I have a Combobox with a rowsource and I want to add a new and static item in that combobox, like 'abc' for example.
> So, if in the rowsource I have 4 items, i will have 5, where one of them is 'abc'
>
> How can I do it?
>
> Regards,


How to create a "auto-fill" style combobox AND allows to add value not found



Create a combobox class and add the following:


In the InterActive Event of the ComboBox:


LOCAL lnStyle, lnLastKey, lcDisplayValue
lnLastKey=lastkey()
lnStyle = this.style
IF this.style = 2
    this.style = 0
ENDI
IF (lnLastKey>=32 and lnLastKey<=126)
    IF this.selstart>=1
        lcDisplayValue=substr(this.displayvalue,1,this.selstart-1)+(chr(lnLastKey))
    ELSE
        lcDisplayValue=(chr(lnLastKey))+allt(this.displayvalue)
    ENDI
    IF empty(lcDisplayValue)
        lcDisplayValue=allt(chr(lnLastKey))
    ENDI
    FOR i = 1 to this.listcount
            If Upper(lcDisplayValue) == Upper(Substr(This.List(i),1,Len(lcDisplayValue)))
                This.DisplayValue=This.List(i)
                This.SelStart=Len(lcDisplayValue)
                nlLength=Len(Allt(This.DisplayValue))-Len(lcDisplayValue)
                This.SelLength=Iif(nlLength <0,0,nlLength)
                this.lastdisplayvalue = this.displayvalue
                this.lastselstart = this.selstart
                this.lastsellength = this.sellength
                RETURN
            ENDI
    ENDFOR
ENDIf



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
                Tableupdate(1,.T.,cTableName)
            ENDIF
        this.Requery() && To reset the display value
        Else
            Store '' To This.DisplayValue
        Endif
    Endif
ENDIF



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)

**********************
Note : this code was also modified to accomodate spaces in a name.



Mike Gagnon
Refox XI +(English version)

ENTIRE THREAD

BASIC QUESTION - NEW ITEM IN A COMBOBOX Posted by Jhon Thomas @ 6/28/2011 10:44:02 PM
RE: BASIC QUESTION - NEW ITEM IN A COMBOBOX Posted by Mike Gagnon @ 6/28/2011 10:48:52 PM
RE: BASIC QUESTION - NEW ITEM IN A COMBOBOX Posted by Tamar Granor @ 6/30/2011 10:41:05 PM