PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Haakon Birkeland on September 22, 2005, 06:27:19 PM

Title: Auto complete problem
Post by: Haakon Birkeland on September 22, 2005, 06:27:19 PM
I have the following code for auto complete of a textbox. My problem is that it does not handle the backspace or delete key without having to write extra code in the keyup event.
Is there any way to handle it and have all the related code in one event?


Function JOBFORM_CUSTTXT_EN_CHANGE ( _
                                  ControlIndex   As Long,  _  ' index in Control Array
                                  hWndForm       As Dword, _  ' handle of Form
                                  hWndControl    As Dword, _  ' handle of Control
                                  idTextControl  As Long   _  ' identifier of text control
                                  ) As Long
Local lIndex, Count, CursorLocation As Long
  Local TempStr As String
   If gBackSpace Then Exit Function
   TempStr = FF_TextBox_GetText( HWND_JOBFORM_CUSTTXT)
  CursorLocation = FF_TextBox_GetSelStart(HWND_JOBFORM_CUSTTXT)
TempStr = Mid$(TempStr,1,CursorLocation)
  Count =  UBound(gCustomers())
  ' Search the current item in the list
  For lIndex = 0 To Count
    If InStr(1, Mid$(UCase$(gCustomers(lIndex)),1,Len(TempStr)), UCase$(TempStr)) > 0 Then
      FF_TextBox_SetText HWND_JOBFORM_CUSTTXT, ""
      FF_TextBox_SetText HWND_JOBFORM_CUSTTXT, gCustomers(lIndex)
      FF_TextBox_SetSel HWND_JOBFORM_CUSTTXT, Len(TempStr), Len(gCustomers(lIndex))
      End If
  Next lIndex

End Function


thanx
Bert
Title: Auto complete problem
Post by: Haakon Birkeland on September 22, 2005, 06:39:45 PM
Forget it.
Keyboard moving before brain in gear. I put everything in Key_up works like charm.

Bert
Title: Auto complete problem
Post by: Roger Garstang on September 23, 2005, 12:37:11 AM
Yeah, I wrote some autocomplete combobox code that is probably on both here and PB's forum.  Here is the last version I had made for somebody in FF:  (Key_Down can't be used too much cause Copy/Paste and highlighted text changes that effect more than one char)


Function FORM1_PORT_CBN_EDITCHANGE (ControlIndex As Long, hWndForm As Dword, hWndControl As Dword, idComboBox As Dword) As Long
Local searchResult As Long
Local lengthComboString As Dword
Local comboString As String
Static previousSize As Dword
Static preventLoop As Dword

If preventLoop = 0 Then
   preventLoop = 1
   comboString= FF_Control_GetText(HWND_FORM1_PORT)

   lengthComboString = Len(comboString)
   If lengthComboString > previousSize Then
       searchResult= SendMessage(HWND_FORM1_PORT, %CB_SELECTSTRING, -1, StrPtr(comboString))
       If searchResult = %CB_ERR Then FF_Control_SetText(HWND_FORM1_PORT, comboString)
   End If
   SendMessage(HWND_FORM1_PORT, %CB_SETEDITSEL, 0, MakDwd(lengthComboString,-1))
   previousSize = lengthComboString
   preventLoop = 0
End If  
End Function
Title: Auto complete problem
Post by: Haakon Birkeland on September 23, 2005, 01:41:58 AM
My code is for a textbox you store all the entries in a string array and will look thru the array and autofill. Simple but does what I need

thanx anyways
bert
Title: Auto complete problem
Post by: Roger Garstang on September 23, 2005, 03:21:30 AM
Same concept, just using Edit Box messages instead of Combo and putting your Search functions for the string array in the "If lengthComboString > previousSize"  block.