Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Combo box bound to an array
Message
 
 
To
12/01/2008 14:38:42
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01281347
Message ID:
01281370
Views:
14
Thank you very much. I will try your code.

>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
>
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform