Jump to content

Recommended Posts

Posted

Trying to build an autocomplete script but finding that I can't click inside the listview box to select an item.

What am I missing ?

#include <GuiConstants.au3>
#include <file.au3>
#include <Array.au3>
Dim $aRecords,$x,$sFilePath,$oldvalue,$testvalue

$sFilePath = "C:\temp\autocomplete.txt"

;window
    GuiCreate("autocomplete",200,250)
    
;label
;------------
    $Input = GuiCtrlCreateInput("", 10, 20, 175, 20, 0x1000)
    
; list
;-----------
    $listView = GuiCtrlCreateListView("key|text",10, 45, 175,190)

; populate listview
GetList("")

Func GetList($testvalue)
    $listView = GuiCtrlCreateListView("key|text",10, 45, 175,190)
    $testvalue = StringStripWS(StringLower($testvalue),8)
    $len = StringLen ($testvalue)
    $i = 1
    
    If Not _FileReadToArray($sFilePath,$aRecords) Then
      ;MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)   
     ; Exit
      Dim $aRecords
      $aRecords = _ArrayCreate ( "a_item2|col21","b_item2|col22","c_item2|col23"  )
      $i=0
    EndIf
    For $x = $i to Ubound($aRecords)-1
        $Temp = StringStripWS(StringLower($aRecords[$x]),8)
        $Temp = StringReplace($Temp,"function", "")
        If $len > 0  Then
            If StringLeft ($Temp,$len ) = $testvalue Then
                GuiCtrlCreateListViewItem($Temp, $listView)
            EndIf
        Elseif $len = 0 Then
            GuiCtrlCreateListViewItem($Temp, $listView)
        EndIf   
    Next
EndFunc; GetList

; GUI LOOP
GuiSetState()

$oldvalue = GUICtrlRead ($Input)
Do
    $msg = GUIGetMsg ()
    $testvalue = GUICtrlRead ($Input)
    if $testvalue <> $oldvalue then GetList($testvalue)
    $oldvalue = $testvalue
;MsgBox(0,"listview", "clicked="& GUICtrlGetState($listview),2)
Until $msg = $GUI_EVENT_CLOSE
Posted

#include <GuiConstants.au3>
#include <file.au3>
#include <Array.au3>
Dim $aRecords,$x,$sFilePath,$oldvalue,$testvalue

$sFilePath = "C:\temp\autocomplete.txt"

;window
    GuiCreate("autocomplete",200,250)
    
;label
;------------
    $Input = GuiCtrlCreateInput("", 10, 20, 175, 20, 0x1000)
    
; list
;-----------
;~   $listView = GuiCtrlCreateListView("key|text",10, 45, 175,190)

; populate listview
GetList("")

; GUI LOOP
GuiSetState()

$oldvalue = GUICtrlRead ($Input)
Do
    $msg = GUIGetMsg ()
    $testvalue = GUICtrlRead ($Input)
    if $testvalue <> $oldvalue then GetList($testvalue)
    $oldvalue = $testvalue
;MsgBox(0,"listview", "clicked="& GUICtrlGetState($listview),2)
Until $msg = $GUI_EVENT_CLOSE

Func GetList($testvalue)
    $listView = GuiCtrlCreateListView("key|text",10, 45, 175,190)
    $testvalue = StringStripWS(StringLower($testvalue),8)
    $len = StringLen ($testvalue)
    $i = 1
    
    If Not _FileReadToArray($sFilePath,$aRecords) Then
     ;MsgBox(4096,"Error", " Error reading log to Array  error:" & @error)   
    ; Exit
      Dim $aRecords
      $aRecords = _ArrayCreate ( "a_item2|col21","b_item2|col22","c_item2|col23"  )
      $i=0
    EndIf
    For $x = $i to Ubound($aRecords)-1
        $Temp = StringStripWS(StringLower($aRecords[$x]),8)
        $Temp = StringReplace($Temp,"function", "")
        If $len > 0  Then
            If StringLeft ($Temp,$len ) = $testvalue Then
                GuiCtrlCreateListViewItem($Temp, $listView)
            EndIf
        Elseif $len = 0 Then
            GuiCtrlCreateListViewItem($Temp, $listView)
        EndIf   
    Next
EndFunc; GetList

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Posted

Thanks that helps some.

Unfortunately when I enter a value like "b" it selects the b_item and then when I click on the listview the value changes back to a_item

I don't understand how this listview is supposed to work.

is this a bug in Listview ?

Posted

No bug, you have to tell it you want to be able to edit i.e. $LVS_EDITLABELS

<{POST_SNAPBACK}>

I changed listview line to be :

$listView = GuiCtrlCreateListView("key|text",10, 45, 175,190,$LVS_EDITLABELS)

but it still behaves as before, and there seems to be no way to capture listview selection .

Each try tells me $listview has not been declared, but if I declare it then the click in listview doesn't work.

Isn't there someway to have a dynamic listview where the value can be clicked for selection and retrieved for use ?

Posted (edited)

I think it has something to do with the fact that you're recreating the listview everytime you call GetList. Create it in the beginning and use GetList to update it using GuiCtrlSetData.

Also, use something like this in your Do loop:

Do
    $msg = GUIGetMsg ()
    If $msg = $Input Then
        $testvalue = GUICtrlRead ($Input)
        if $testvalue <> $oldvalue then GetList($testvalue)
        $oldvalue = $testvalue
    EndIf
;MsgBox(0,"listview", "clicked="& GUICtrlGetState($listview),2)
Until $msg = $GUI_EVENT_CLOSE
Edited by c0deWorm

My UDFs: ExitCodes

Posted

I think it has something to do with the fact that you're recreating the listview everytime you call GetList.  Create it in the beginning and use GetList to update it using GuiCtrlSetData.

Also, use something like this in your Do loop:

Do
    $msg = GUIGetMsg ()
    If $msg = $Input Then
        $testvalue = GUICtrlRead ($Input)
        if $testvalue <> $oldvalue then GetList($testvalue)
        $oldvalue = $testvalue
    EndIf
;MsgBox(0,"listview", "clicked="& GUICtrlGetState($listview),2)
Until $msg = $GUI_EVENT_CLOSE

<{POST_SNAPBACK}>

did you try your suggestion? I think things are getting worse ?
Posted

looks like $LVS_EDITLABELS doesn't work, it goes into edit mode but doesn't save what is typed.

<{POST_SNAPBACK}>

DOA ............ :whistle:
Posted

did you try your suggestion?  I think things are getting worse ?

No I didn't, but I'm pretty sure it would be more efficient and use less CPU to test for something happening in the input box before reading from it instead of just constantly reading from it.

All I did was add the "if" and have it check the new value against the old value. There's no need to do anything if the text hasn't changed. Clicking in the input box would trigger an $input event, but not change the value of it.

My UDFs: ExitCodes

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
  • Recently Browsing   0 members

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