Jump to content

ComboBox Auto Complete provides suggestions


Recommended Posts

Hello,
try to use _GUICtrlComboBox_AutoComplete, but Help example completes name if find exact word.

Is there any way to implement suggestions, and filtering, while user write only part of word ?
eg: type word 'ja', FIND and suggest, 'java' AND 'Pijama'

thank you for any help,
m.

Edited by myspacee
bad english
Link to comment
Share on other sites

1 hour ago, mikell said:

May I suggest this instead   :D

 

good scripts..., however they do not solve what OP asked in the first post, that is the finding of words from the list, that contain the portion of what you are typing even if it appears in the middle of the words and not only the words that begins with that part.
It seems that scripts in your link finds only words that begins with what you are typing instead.
Of course those are, however, very nice scripts!

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Hello,
thank you for reply.

Play with code and obtain this :

;~ https://www.autoitscript.com/forum/topic/157790-trying-to-make-autocomplete-like-google-search-in-a-text-box/

#include <GUIConstantsEx.au3>
#include <Array.au3>
#Include <GuiListBox.au3>
#include <file.au3>

#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>


;~ ///////////////////////////////////////////////////
;~ //       temp file with some data
;~ ///////////////////////////////////////////////////
 ; Open the file for writing append
 Local $hFileOpen = FileOpen("Data.ini", $FO_APPEND)
 If $hFileOpen = -1 Then
     MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the  file.")
     Return False
 EndIf

 ; Write data to the file using the handle returned by FileOpen.
 FileWriteLine($hFileOpen, "Abyssinian")
 FileWriteLine($hFileOpen, "Adelie Penguin")
 FileWriteLine($hFileOpen, "Affenpinscher")
 FileWriteLine($hFileOpen, "Afghan Hound")
 FileWriteLine($hFileOpen, "African Bush Elephant")
 FileWriteLine($hFileOpen, "African Civet")
 FileWriteLine($hFileOpen, "African Clawed Frog")
 FileWriteLine($hFileOpen, "African Forest Elephant")
 FileWriteLine($hFileOpen, "African Palm Civet")
 FileWriteLine($hFileOpen, "African Penguin")
 FileWriteLine($hFileOpen, "African Tree Toad")
 FileWriteLine($hFileOpen, "African Wild Dog")
 FileWriteLine($hFileOpen, "Ainu Dog")
 FileWriteLine($hFileOpen, "Airedale Terrier")
 FileWriteLine($hFileOpen, "Akbash")
 FileWriteLine($hFileOpen, "Akita")

 FileClose($hFileOpen)


;~ ///////////////////////////////////////////////////
;~ //       define vars
;~ ///////////////////////////////////////////////////
Global $hGUI, $hInput, $hList, $sPartialData, $asKeyWords[1000]

;~ ///////////////////////////////////////////////////
;~ //       go read .ini file with words
;~ ///////////////////////////////////////////////////
Keywords()

;~ ///////////////////////////////////////////////////
;~ //       GUI
;~ ///////////////////////////////////////////////////
$hGUI = GUICreate("Example", 200, 400)
$hInput = GUICtrlCreateInput("", 5, 5, 190, 20)
$hList = GUICtrlCreateList("", 5, 30, 190, 325, BitOR(0x00100000, 0x00200000))
$hButton = GUICtrlCreateButton("Read", 60, 360, 80, 30)
$hUP = GUICtrlCreateDummy()
$hDOWN = GUICtrlCreateDummy()
$hENTER = GUICtrlCreateDummy()
GUISetState(@SW_SHOW, $hGUI)

; Set accelerators for Cursor up/down and Enter
Dim $AccelKeys[3][2]=[["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER]]
GUISetAccelerators($AccelKeys)

$sCurr_Input = ""
$iCurrIndex = -1


;~ ///////////////////////////////////////////////////
;~ //       MAIN
;~ ///////////////////////////////////////////////////
While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hList
            $sChosen = GUICtrlRead($hList)
            If $sChosen <> "" Then GUICtrlSetData($hInput, $sChosen)
        Case $hButton
            If $sPartialData <> "" Then
                $sFinal = GUICtrlRead($hInput)
                If _ArraySearch($asKeyWords, $sFinal) > 0 Then
                    MsgBox(0, "Chosen", $sFinal)
                EndIf
            EndIf
        Case $hUP
            If $sPartialData <> "" Then
                $iCurrIndex -= 1
                If $iCurrIndex < 0 Then $iCurrIndex = 0
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hDOWN
            If $sPartialData <> "" Then
                $iTotal = _GUICtrlListBox_GetCount($hList)
                $iCurrIndex += 1
                If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hENTER
            If $iCurrIndex <> -1 Then
                $sText = _GUICtrlListBox_GetText($hList, $iCurrIndex)
                GUICtrlSetData($hInput, $sText)
                $iCurrIndex = -1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
    EndSwitch

    ; If input has changed, refill list with matching items
    If GUICtrlRead($hInput) <> $sCurr_Input Then
        CheckInputText()
        $sCurr_Input = GUICtrlRead($hInput)
    EndIf

WEnd

Func CheckInputText()
   $sPartialData = "|" ; Start with delimiter so new data always replaces old
   Local $sInput = GUICtrlRead($hInput)

   If $sInput <> "" Then

      $iRows = UBound($asKeyWords, $UBOUND_ROWS)
      For $i = 0 To $iRows - 1
         If StringInStr($asKeyWords[$i], $sInput) <> 0 Then $sPartialData &= $asKeyWords[$i] & "|"
      Next
      GUICtrlSetData($hList, $sPartialData)

   Else
      GUICtrlSetData($hList, "")
   EndIf
EndFunc   ;==>CheckInputText

Func Keywords()

   Local $sData

   Local $aInput
   $file = "Data.ini"

   _FileReadToArray($file, $aInput)
   For $i = 1 to UBound($aInput) -1
      $asKeyWords[$i] = $aInput[$i]
      $sData &= $asKeyWords[$i] & "|"
   Next

    GUICtrlSetData($hList, $sData)
    $iCurrIndex = -1
    _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)

EndFunc   ;==>Keywords

I need this to read a file with a list of words. Anyway to doubleclick to select item ?

thank you again,
m.

Link to comment
Share on other sites

For the doubleclick :

;~ https://www.autoitscript.com/forum/topic/157790-trying-to-make-autocomplete-like-google-search-in-a-text-box/

#include <GUIConstantsEx.au3>
#include <Array.au3>
#Include <GuiListBox.au3>
#include <file.au3>

#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <WindowsConstants.au3>


;~ ///////////////////////////////////////////////////
;~ //       temp file with some data
;~ ///////////////////////////////////////////////////
 ; Open the file for writing append
 Local $hFileOpen = FileOpen("Data.ini", $FO_APPEND)
 If $hFileOpen = -1 Then
     MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the  file.")
     Exit
 EndIf

 ; Write data to the file using the handle returned by FileOpen.
 FileWriteLine($hFileOpen, "Abyssinian")
 FileWriteLine($hFileOpen, "Adelie Penguin")
 FileWriteLine($hFileOpen, "Affenpinscher")
 FileWriteLine($hFileOpen, "Afghan Hound")
 FileWriteLine($hFileOpen, "African Bush Elephant")
 FileWriteLine($hFileOpen, "African Civet")
 FileWriteLine($hFileOpen, "African Clawed Frog")
 FileWriteLine($hFileOpen, "African Forest Elephant")
 FileWriteLine($hFileOpen, "African Palm Civet")
 FileWriteLine($hFileOpen, "African Penguin")
 FileWriteLine($hFileOpen, "African Tree Toad")
 FileWriteLine($hFileOpen, "African Wild Dog")
 FileWriteLine($hFileOpen, "Ainu Dog")
 FileWriteLine($hFileOpen, "Airedale Terrier")
 FileWriteLine($hFileOpen, "Akbash")
 FileWriteLine($hFileOpen, "Akita")

 FileClose($hFileOpen)


;~ ///////////////////////////////////////////////////
;~ //       define vars
;~ ///////////////////////////////////////////////////
Global $hGUI, $hInput, $hList, $sPartialData, $asKeyWords[1000]

;~ ///////////////////////////////////////////////////
;~ //       go read .ini file with words
;~ ///////////////////////////////////////////////////
Keywords()

;~ ///////////////////////////////////////////////////
;~ //       GUI
;~ ///////////////////////////////////////////////////
$hGUI = GUICreate("Example", 200, 400)
$hInput = GUICtrlCreateInput("", 5, 5, 190, 20)
$hList = GUICtrlCreateList("", 5, 30, 190, 325, BitOR(0x00100000, 0x00200000))
$hButton = GUICtrlCreateButton("Read", 60, 360, 80, 30)
$hUP = GUICtrlCreateDummy()
$hDOWN = GUICtrlCreateDummy()
$hENTER = GUICtrlCreateDummy()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState(@SW_SHOW, $hGUI)

; Set accelerators for Cursor up/down and Enter
Dim $AccelKeys[3][2]=[["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER]]
GUISetAccelerators($AccelKeys)

$sCurr_Input = ""
$iCurrIndex = -1


;~ ///////////////////////////////////////////////////
;~ //       MAIN
;~ ///////////////////////////////////////////////////
While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
;~         Case $hList
;~             $sChosen = GUICtrlRead($hList)
;~             If $sChosen <> "" Then GUICtrlSetData($hInput, $sChosen)
        Case $hButton
            If $sPartialData <> "" Then
                $sFinal = GUICtrlRead($hInput)
                If _ArraySearch($asKeyWords, $sFinal) > 0 Then
                    MsgBox(0, "Chosen", $sFinal)
                EndIf
            EndIf
        Case $hUP
            If $sPartialData <> "" Then
                $iCurrIndex -= 1
                If $iCurrIndex < 0 Then $iCurrIndex = 0
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hDOWN
            If $sPartialData <> "" Then
                $iTotal = _GUICtrlListBox_GetCount($hList)
                $iCurrIndex += 1
                If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hENTER
            If $iCurrIndex <> -1 Then
                $sText = _GUICtrlListBox_GetText($hList, $iCurrIndex)
                GUICtrlSetData($hInput, $sText)
                $iCurrIndex = -1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
    EndSwitch

    ; If input has changed, refill list with matching items
    If GUICtrlRead($hInput) <> $sCurr_Input Then
        CheckInputText()
        $sCurr_Input = GUICtrlRead($hInput)
    EndIf

WEnd

Func CheckInputText()
   $sPartialData = "|" ; Start with delimiter so new data always replaces old
   Local $sInput = GUICtrlRead($hInput)

   If $sInput <> "" Then

      $iRows = UBound($asKeyWords, $UBOUND_ROWS)
      For $i = 0 To $iRows - 1
         If StringInStr($asKeyWords[$i], $sInput) <> 0 Then $sPartialData &= $asKeyWords[$i] & "|"
      Next
      GUICtrlSetData($hList, $sPartialData)

   Else
      GUICtrlSetData($hList, "")
   EndIf
EndFunc   ;==>CheckInputText

Func Keywords()

    Local $sData, $file = "Data.ini"

    Local $aInput = FileReadToArray($file)
    $aInput = _ArrayUnique($aInput)
    For $i = 0 to UBound($aInput) -1
        $asKeyWords[$i] = $aInput[$i]
        $sData &= $asKeyWords[$i] & "|"
    Next

    GUICtrlSetData($hList, $sData)
    $iCurrIndex = -1
    _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)

EndFunc   ;==>Keywords


Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $iCode = BitShift($wParam, 16)
    Local $iID = BitAND($wParam, 0x0000FFFF)

    If $iID = $hList And $iCode = $LBN_DBLCLK Then
        $sChosen = GUICtrlRead($hList)
        If $sChosen <> "" Then GUICtrlSetData($hInput, $sChosen)
    EndIf
EndFunc

Not that I changed _FileReadToArray to FileReadToArray native function (cleaner)

 

Edited by jguinch
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...