Jump to content

AutoComplete in EditControl


Buffo
 Share

Recommended Posts

Hi,

today there's a new problem for me ;-)

I have a list with words (which can vary in quantity) in an array and an Edit-Control.

In this Edit-Control something like autocomplete should happen.

Example word list: america, africa, asia, europe

After the input of "A" should the Edit-Control show the following:

aMERICA (whereas the big letters should be marked so that they are overwritten by the next keystroke)

Then I press "F" and the Edit-Control shoud show:

afRICA (the big letters are marked).

I tried it with _GuiCtrlEditSetSel():

$input = GuiCtrlRead($edit)
If $input <> $lastinput Then 
-If $input <> "" Then
--For $i = 1 To $array[0]; number of items in array
---If StringLeft($array[$i], StringLen($input)) = $input Then 
----GuiCtrlSetData($edit, $array[$i])
----_GuiCtrlEditSetSel($edit, StringLen($array[$i]), StringLen($sCommand))
----ExitLoop
---EndIf
--Next
-EndIf
EndIf

This code is checked several times per second and works great, but unfortunately the next

time the content is checked the new value of the edit is of course the whole word and the

selection is gone.

Any suggestions?

I hope you understand what I mean ;-)

Regards,

Buffo

BTW:

GuiCtrlSetOnEvent($edit, "test")

Func test()

...

EndFunc

When will the func "test" be called? I thought on every keystroke but all I figured out is the call if "enter" is pressed? (Opt("GuiOnEventMode", 1) is set!)

Edited by Buffo
Link to comment
Share on other sites

Thx for your reply.

I know that I will have to reset $lastinput, but I don't know how to different between a "real" input and the input of the autocompletetion.

A few mistakes were in the code above that happened by shorten and simplify the code. Here a new one for better understanding.

Opt("GuiOnEventMode," 1)

Global $lastinput

GuiCreate(...)
$edit = GuiCtrlCreateEdit(...)
GuiSetState(@SW_SHOW)

$array = ...

While 1
-Sleep(250)
-If $lastinput <> GuiCtrlRead($edit) Then AutoComplete()
WEnd 

Func AutoComplete()
-$input = GuiCtrlRead($edit)
-If $input <> $lastinput And $input <> "" Then 
--$lastinput = $input
--For $i = 1 To $array[0]; number of items in array
---If StringLeft($array[$i], StringLen($input)) = $input Then 
----GuiCtrlSetData($edit, $array[$i])
----_GuiCtrlEditSetSel($edit, StringLen($array[$i]), StringLen($sCommand))
----ExitLoop
---EndIf
--Next
-EndIf
EndFunc

Regards,

Buffo

BTW: I got the answer myself for the "btw"-question before: It's only for the "click"-event. Strangely I thought that there are standard-actions for different controls and for the edit-control, i thought it was an keypress-action. I don't know from where are my thoughts (maybe VB?)

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...