Jump to content

Searching in ListView


Recommended Posts

I am making a media player and I want to create a search thingie for it like iTunes

so if you type an 'a' in my search input all items who don't start with an 'a' go away.

That's how I want it to be.. Well it's not really working...

I got somewhere with the following code:

#include <GUIConstants.au3>
#include <File.au3>
#Include <GuiListView.au3>
$playlistfile = @DesktopDir&'\playlist1.ml'
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 447, 193, 125)
$searchin = GUICtrlCreateInput("", 56, 24, 121, 21)
$playlist = GUICtrlCreateListView("Artist|Title|Album|Path", 16, 72, 610, 358)
GUICtrlSendMsg(-1, 0x101E, 0, 150)
GUICtrlSendMsg(-1, 0x101E, 1, 150)
GUICtrlSendMsg(-1, 0x101E, 2, 150)
GUICtrlSendMsg(-1, 0x101E, 3, 150)
_SetListItems($playlistFile, $playlist)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$handle = GUICtrlGetHandle($playlist)
While 1
    if GUICtrlRead($searchin)<>'' Then
        $i = 0
        $lines = _FileCountLines($playlistFile)
        _GUICtrlListView_DeleteAllItems($handle)
        While GUICtrlRead($searchin)<>''
            $i = $i + 1
            $line = _FileReadLine($playlistFile, $i)
            if StringLeft($line, StringLen(GUICtrlRead($searchin))) = GUICtrlRead($searchin) Then
                if _SearchForItem($playlist, $line) = 1 then GUICtrlCreateListViewItem($line, $playlist)
            EndIf
            
            if $i = $lines then $i = 0
        WEnd
    EndIf
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func _SetListItems($sFile, $sList)
    $file = FileOpen($sFile, 0)
    While 1
    $list = FileReadLine($file)
    if @error then exitloop
    GUICtrlCreateListViewItem($list, $sList)
    WEnd
    FileClose($file)
EndFunc

Func _SearchForItem($sList, $sText)
    $handle = GUICtrlGetHandle($sList)
    if _GUICtrLListView_FindText($handle, $sText) = -1 then return 1
    return 0
EndFunc

Func _FileReadLine($sFile, $sLine=1)
    $file = FileOpen($sFile, 0)
    if $file = -1 then return SetError(-1, 0)
    $sReturn = FileReadLine($file, $sLine)
    FileClose($file)
    return $sReturn
EndFunc

Please help???

Edited by ludocus
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...