Jump to content

Search as you type


Recommended Posts

Hello All,

I have searched and so far I am coming up empty.

Here is the scenario.

I have an array with roughly 600 entries that are displayed in a ListView. Even with sorting the list alphabetically it is still cumbersome to fine things. What I would like is a text box that as you type the items in ListView are narrowed down to the match what is typed in the textbox. The more you type the narrower the results.

Any ideas?

Link to comment
Share on other sites

yea, I made a thread about doing this too, but turns out its actually complicated.. I didn't get an answer though, someone said they dunnit though..

[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Link to comment
Share on other sites

I can imagine its complicated. Lets just hope whoever sad they dunnit can remember how and post a little about it.

Maybe this will help. Here is a VB solution. Now to adapt it over for Autoit.

option Explicit

'Start a new Standard-EXE project.
'Add a textbox and a listbox control to form 1
'Add the following code to form1:

private Declare Function SendMessage Lib "User32" _
        Alias "SendMessageA" (byval _
        hWnd as Long, _
        byval wMsg as Integer, _
        byval wParam as string, _
        lParam as Any) as Long

Const LB_FINDSTRING = &H18F

private Sub Form_Load()

    With List1
        .Clear
        .AddItem "RAM"
        .AddItem "rams"
        .AddItem "RAMBO"
        .AddItem "ROM"
        .AddItem "Roma"
        .AddItem "Rome"
        .AddItem "Rommel"
        .AddItem "Cache"
        .AddItem "Cash"
    End With

End Sub

private Sub Text1_Change()
    List1.ListIndex = SendMessage(List1.hWnd, LB_FINDSTRING, _
                      Text1, byval Text1.Text)
End Sub
Edited by ChuckS
Link to comment
Share on other sites

well, errmm.. take alook at this?

http://www.autoitscript.com/forum/index.php?s=&showtopic=47180&view=findpost&p=353256

[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Link to comment
Share on other sites

well, errmm.. take alook at this?

http://www.autoitscript.com/forum/index.php?s=&showtopic=47180&view=findpost&p=353256
You could do something like this which is just to show one way.

#include <GUIConstants.au3>
#include <GUILIST.AU3>

#Region ### START Koda GUI section ### Form=
$Form3 = GUICreate("Form3", 413, 298, 303, 219)
$Input1 = GUICtrlCreateInput("Input1", 110, 21, 139, 21)
Global $List1 = GUICtrlCreateList("", 120, 79, 121, 188)
GUICtrlSetData(-1,'appalling|appaloosa|appanages|apparatus|appealers|appealing|appearers|appearing' & _
'|appea_sers|appeasing|appellant|appellate|appellees|appellors|appendant|appending|appertain|appes' & _
'tats|appetency|appetites|appetizer|applauded|applauder|applejack|appliance|applicant|appli' & _
'qued|appliques|appointed|appointee|appointer|apportion|appraisal|appraised|appraiser|appra' & _
'ises|apprehend|apprisers|apprising|approbate|approvals')
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$lastword = ''
Global $word

While 1
    $word  = GUICtrlRead($Input1)
    If $lastword <> $word Then  findline()
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd


Func findline()
    Local $Afind = -1
    $listlen =  _GUICtrlListCount($List1)
    ConsoleWrite('no of items = ' & $listlen & @CRLF)

    For $nl = 0 To $listlen - 1
        If StringInStr(_GUICtrlListGetText($List1,$nl),$word) Then
            $Afind = $nl
            Exitloop
        EndIf
        
        
    Next
    If $Afind >= 0 And $nl < $listlen - 1 Then
        For $ml = $nl + 1 To $listlen - 1
            If Not StringInStr(_GUICtrlListGetText($List1,$nl),$word) Then
                $Afind = $ml - 1
                Exitloop
            EndIf
        Next
    EndIf
    If $Afind > -1 Then _GUICtrlListSetTopIndex($List1, $Afind)
    ConsoleWrite($afind & @CRLF)
        $lastword = $word
endfunc

EDIT: Corrected line to $Afind = $ml - 1; (- 1 was missing)

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • 2 weeks later...

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