Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Combo box bound to an array
Message
De
13/01/2008 11:15:38
 
 
À
12/01/2008 14:38:42
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01281347
Message ID:
01281464
Vues:
19
This is great code Marcia, thanks for sharing.


>What happens that if the value assigned to the combo box is not in the array, the combo box value is empty. Is it possible to make the value, even if it is not in the array, to be set/stick?
>
>
>**************************************************
>*-- Class:        cbonotinlist
>*-- ParentClass:  combobox
>*-- BaseClass:    combobox
>*-- allows selection of an item not in the combo's list to be used as its controlsource...only works if the combo's bound column is 1
>*
>Define Class cbonotinlist As combobox
>
>  *-- Used to save the control source of the combo before the control is unbound
>  ccontrolsource = ""
>  cOldExact = ""
>  uOldVal = ""
>  Name = "cbonotinlist"
>
>  *-- Called from Valid...it updates the "bound" field
>  Procedure updatecontrolsource
>    Local lcAlias, lcControlSource
>    With This
>      If ! Empty( .ccontrolsource )
>        lcAlias = Juststem( .ccontrolsource )
>        If Upper( Alltrim( lcAlias ) ) = 'THISFORM'
>          lcControlSource = .ccontrolsource
>          Store .DisplayValue To &lcControlSource
>        Else
>          Replace ( .ccontrolsource ) With .DisplayValue In ( lcAlias )
>        Endif
>      Endif
>    Endwith
>  Endproc
>
>  *-- Updates display value from the field in the underlying table if this is a "bound" control
>  Procedure refreshdisplayvalue
>    Local lcControlSource
>    With This
>      If ! Empty( .ccontrolsource )
>        lcControlSource = .ccontrolsource
>        .DisplayValue = &lcControlSource
>      Endif
>    Endwith
>  Endproc
>
>  Procedure HandleKey
>    LOCAL lcSofar, lnSelStart, lnSelLength, lnRow
>    WITH This
>	*** Handle backspace key
>	IF LASTKEY() = 127
>		.SelStart = .SelStart - 1
>	ENDIF	
>	*** Get the value typed in so far
>	lnSelStart = .SelStart
>	lcSofar =  LEFT( .DisplayValue, lnSelStart )
>	*** Find a match in column #1 of the combo's internal list
>	FOR lnRow = 1 TO .ListCount
>		IF UPPER( .List[ lnRow, 1 ] ) = UPPER( lcSoFar )
>			.ListIndex = lnRow
>			EXIT
>		ENDIF
>	ENDFOR		
>	*** Highlight the portion of the value after the insertion point
>	.SelStart = lnSelStart
>	lnSelLength = LEN( ALLTRIM( .DisplayValue ) ) - lnSelStart
>	IF lnSelLength > 0
>		.SelLength =  lnSelLength	
>	ENDIF	
>    ENDWITH
>  Endproc
>
>  Procedure KeyPress
>    *** handle the key...IOW, find the closest match in the list
>    IF This.SelStart > 0
>	IF ( LASTKEY() > 31 AND LASTKEY() < 128 ) OR ( LASTKEY() = 7 )
>	   This.HandleKey()
>	ENDIF
>    ENDIF
>  EndProc
>
>  Procedure Init
>    If DoDefault()
>      With This
>        .ccontrolsource = .ControlSource
>        .ControlSource = ''
>      Endwith
>    Endif
>  Endproc
>
>  Procedure Valid
>    This.updatecontrolsource()
>  Endproc
>
>  Procedure Refresh
>    This.refreshdisplayvalue()
>  Endproc
>
>  Procedure GotFocus
>    If Lower( This.Parent.BaseClass ) = 'column'
>      *** This is needed so it will work in a grid
>      ComboBox::GotFocus()
>      This.refreshdisplayvalue()
>      Nodefault
>    Else
>      This.uOldVal = .Value
>      combobox::GotFocus()
>      This.SelStart = 0
>      This.SelLength = LEN( This.Text )
>      .cOldExact = SET( 'EXACT' )
>      SET EXACT OFF
>      NODEFAULT
>    Endif
>  Endproc
>Enddefine
>
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform