Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Combo Box incremental search
Message
 
To
02/06/2003 17:31:43
Stephen Hunt
Admit Computer Services Inc.
Farmingdale, New York, United States
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00795427
Message ID:
00795486
Views:
17
Stephen,

You can set the combobox's Style property = 0 (Dropdown Combo) and place code in the KeyPress method. As the user types the first matching record will display in the combobox.

Here's some cutup, partial code to demonstration. This combobox is sometimes both the requery control for a parameterized SQL statement and the edit control for the updatable cursor. A DO CASE handles some special stituations I found using comboboxes.
PROCEDURE KEYPRESS
LPARAMETERS nKeyCode, nShiftAltCtrl
LOCAL lnIndex,lnStartIndex,lnCursorPosition,lnSelLength
WITH THIS
  DO CASE
    CASE .lDataRequery AND .PARENT.lAddRecord ; &&Adding record & requery combobox - no dropdown
        AND (nKeyCode=-3 AND nShiftAltCtrl=0 ; && Disable F4
        OR nKeyCode=160 AND nShiftAltCtrl=4) && Disable ALT+DOWNARROW
      NODEFAULT

    CASE .SELSTART = 0 AND .lDataRequery AND nKeyCode = 32
      NODEFAULT
      .SELLENGTH = 0
      KEYBOARD "{alt+dnarrow}" PLAIN && Hitting the spacebar opens the dropdown

    CASE .STYLE = 2
      DODEFAULT()

    CASE BETWEEN(nKeyCode, 32, 122) && this does all the work
      lnStartIndex = 1
      IF .SELSTART > 0
        lnStartIndex = .LISTINDEX
      ENDIF
      FOR lnIndex = lnStartIndex TO .LISTCOUNT
        IF UPPER(SUBSTR(.LIST(lnIndex), 1, .SELSTART+ 1)) = ;
            UPPER(SUBSTR(.TEXT, 1, .SELSTART)+CHR(nKeyCode))
          lnCursorPosition = .SELSTART + 1
          .DISPLAYVALUE = .LIST(lnIndex)
          .SELSTART = lnCursorPosition
          lnSelLength = LEN(ALLTRIM(.LIST(lnIndex))) - lnCursorPosition
          IF lnSelLength > 0
            .SELLENGTH = lnSelLength
          ENDIF
          NODEFAULT
          EXIT
        ENDIF
      ENDFOR
 
  ENDCASE
ENDWITH
ENDPROC
>Since VFP 3.0 I have always had problems with the native VFP combo Box. Depending on the speed of the computer the user had, and how fast they would type I sometimes would get different results. Like for instance if I had a combo box based on a states library and on machine 1 I type "NY" the value of the combo box would sometimes go to "NY" sometime go to the first State that started with "Y". I was just wondering if Microsoft has addressed this problem since VFP 3.0 or if anyone has a work around for this.
>
>Thanks For Your Help
>Stephen
Heavy Metal Pedal - click with care
Previous
Reply
Map
View

Click here to load this message in the networking platform