Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Incremental search in listbox
Message
From
28/06/2004 07:08:12
 
 
To
27/06/2004 23:43:03
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00917831
Message ID:
00917881
Views:
14
i have a textbox and a listbox. i want an incremental search in the listbox as the user types in the textbox.

Create a composite class with a textbox and a listbox in a container. This code in the textbox's InteractiveChange:
*** 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.Parent.Search()
  ENDIF   
ENDIF
This code in the container's Search method:
LOCAL lcSofar, lnSelStart, lnSelLength, lnRow

WITH This
  WITH .txtqFill
    *** Handle backspace key
    IF LASTKEY() = 127
      .SelStart = .SelStart - 1
    ENDIF	
    *** Get the value typed in so far
    lnSelStart = .SelStart
    lcSofar =  LEFT( .Value, lnSelStart ) 
    *** Find a match in column #1 of the list portion of this control
  ENDWITH
  WITH .lstSearch
    *** Reset the list index in case we have type ion something that is not
    *** in the list
    .ListIndex = 0
    FOR lnRow = 1 TO .ListCount
      IF UPPER( .List[ lnRow, 1 ] ) = UPPER( lcSoFar )
        .ListIndex = lnRow
        *** Synchronize the contents of the textbox with what is selected
        *** in the list
        This.txtQfill.Value = .Value
	EXIT
      ENDIF
    ENDFOR	
  ENDWITH	
  WITH .txtqFill
    *** Highlight the portion of the value after the insertion point
    .SelStart = lnSelStart
    lnSelLength = LEN( ALLTRIM( .Value ) ) - lnSelStart 
    IF lnSelLength > 0
      .SelLength =  lnSelLength	
    ENDIF	
  ENDWITH
ENDWITH
Previous
Reply
Map
View

Click here to load this message in the networking platform