home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1995 November / PCPRO_NOV95.ISO / code / db / keypress.txt < prev    next >
Encoding:
Text File  |  1995-09-08  |  2.4 KB  |  85 lines

  1.  * This is where most of the missing functionality is restored
  2. * to VFP's rather deficient combo box
  3. LPARAMETERS lnKeyCode, nShiftAltCtrl
  4.  
  5. Local lcOldDisplayValue, llVisibleChar
  6.  
  7. * If the control is a Drop-Down Combo (text box with list)
  8. * and the control is set for incremental searching as the user types
  9. if this.Style = 0 and this.IncrementalSearch
  10.     llVisibleChar = .F.    && Assume a non-visible character
  11.     lcOldDisplayValue = this.DisplayValue    && Save away current value
  12.  
  13.     DO CASE
  14.         * Valid chars include letters, digits, spaces, and apostrophes
  15.         CASE BETWEEN(lnKeyCode, 65, 90);
  16. OR BETWEEN(lnKeyCode, 97, 122);
  17. OR BETWEEN(lnKeyCode, 48, 57);
  18. OR INLIST(lnKeyCode, 32, 39)
  19.             this.SearchKey = this.SearchKey + CHR(lnKeyCode)
  20.             llVisibleChar = .T.
  21.  
  22.         * Backspace - remove the last character
  23.         CASE lnKeyCode = 127
  24.             IF LEN(this.SearchKey) > 0
  25.                 this.SearchKey = LEFT(this.SearchKey,;
  26. LEN(this.SearchKey) - 1)
  27.             ENDIF
  28.  
  29.         * Delete - get rid of the current entry
  30.         CASE lnKeyCode = 7
  31.  
  32.         * Up Arrow - go to previous item in list
  33.         CASE lnKeyCode = 5
  34.             this.ListIndex = max(this.ListIndex - 1, 1)
  35.             this.SearchKey = ""
  36.             lcOldDisplayValue = this.DisplayValue
  37.             
  38.         * Down Arrow - go to next item in list
  39.         CASE lnKeyCode = 24
  40.             this.ListIndex = min(this.ListIndex + 1, this.ListCount)
  41.             this.SearchKey = ""
  42.             lcOldDisplayValue = this.DisplayValue
  43.             
  44.         * Any other key - do nothing at all
  45.         OTHERWISE
  46.             RETURN
  47.     ENDCASE
  48.  
  49.     * Don't automatically let key press enter combo box
  50.     NODEFAULT
  51.  
  52.     * If we have a SearchKey, find it
  53.     IF NOT EMPTY(this.SearchKey)
  54.         this.ListIndex = This.ListFind(this.SearchKey)
  55.     ENDIF
  56.  
  57.     * If we don't have a SearchKey, or it wasn't found
  58.     IF EMPTY(this.SearchKey) OR this.ListIndex = 0
  59.         * If we're not limiting the typed value to list items
  60.         IF NOT this.LimitToList
  61.             this.DisplayValue = this.SearchKey
  62.             this.SelLength = 0
  63.         ELSE
  64.             * Do not add char just typed to search string
  65.             this.SearchKey = LEFT(this.SearchKey,;
  66. LEN(this.SearchKey) - 1)
  67.             this.DisplayValue = lcOldDisplayValue
  68.             
  69.             if this.BeepOnError and llVisibleChar
  70.                 ?? CHR(7)
  71.             endif
  72.         ENDIF
  73.     ELSE
  74.         * Set the new value to the item found in the list
  75.         this.DisplayValue = trim(this.list(this.ListIndex))
  76.     ENDIF
  77.  
  78.     * Select the text in the control
  79.     this.SelStart = LEN(this.SearchKey)
  80.     this.SelLength = LEN(this.DisplayValue)
  81. endif
  82.  
  83. * Update the underlying control source
  84. this.UpdateControlSource
  85.