LerN

Listview search

4 posts in this topic

#1 ·  Posted

Hi, i already posted it before but i didn't get any help ... first i don't want the filtering functions
What i have here a code to search for some names in fact i have more than 5000 name but the code below is just for example ...
The code below just searches for one item in the list and that's the problem 
what i wanted to have , is when i search for ex: name1 it will check the name1 in the listview and if i pressed search again it moves to the next name called for ex: name11

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <Guilistview.au3>

$File = @ScriptDir & "\Namess.ini"
$Create = FileWrite($File,"")
IniWriteSection($File,"Name1","Name = Name1")
IniWriteSection($File,"Name2","Name = Name2")
IniWriteSection($File,"Name3","Name = Name3")
IniWriteSection($File,"Name4","Name = Name4")
IniWriteSection($File,"Name5","Name = Name5")
IniWriteSection($File,"Name6","Name = Name6")
IniWriteSection($File,"Name7","Name = Name7")
IniWriteSection($File,"Name8","Name = Name8")
IniWriteSection($File,"Name9","Name = Name9")
IniWriteSection($File,"Name11","Name = Name10")
IniWriteSection($File,"Name12","Name = Name11")
IniWriteSection($File,"Name13","Name = Name12")
IniWriteSection($File,"Name14","Name = Name13")
IniWriteSection($File,"Name15","Name = Name14")
IniWriteSection($File,"Name16","Name = Name15")
IniWriteSection($File,"Name17","Name = Name16")
IniWriteSection($File,"Name18","Name = Name17")
IniWriteSection($File,"Name19","Name = Name18")
IniWriteSection($File,"Name20","Name = Name19")
IniWriteSection($File,"Name21","Name = Name20")
IniWriteSection($File,"Name21","Name = Name21")
IniWriteSection($File,"Name22","Name = Name22")
IniWriteSection($File,"Name23","Name = Name23")
IniWriteSection($File,"Name24","Name = Name24")
IniWriteSection($File,"Name25","Name = Name25")
IniWriteSection($File,"Name26","Name = Name26")
IniWriteSection($File,"Name27","Name = Name27")
IniWriteSection($File,"Name28","Name = Name28")
IniWriteSection($File,"Name29","Name = Name29")
IniWriteSection($File,"Name30","Name = Name30")

$Form1 = GUICreate("Form1", 615, 352, 192, 124)
$ListView1 = GUICtrlCreateListView("Names", 0, 40, 610, 310)
$Input1 = GUICtrlCreateInput("", 224, 8, 177, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$Button1 = GUICtrlCreateButton("Search", 409, 8, 111, 25)
GUISetState(@SW_SHOW)

_Load()

_GUICtrlListView_SetColumnWidth($ListView1,0,200)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            _Search()
    EndSwitch
WEnd

Func _Load()
$readsectionnames = IniReadSectionNames($File)
For $i = 1 to $readsectionnames[0]
 $readnames = iniread($File,$readsectionnames[$i],"Name","")
 GUICtrlCreateListViewItem($readnames,$ListView1)
Next
EndFunc

Func _Search()
$Search = _GUICtrlListView_FindText($ListView1, Guictrlread($Input1))
_GUICtrlListView_SetItemSelected($ListView1,$Search)
_GUICtrlListView_EnsureVisible($ListView1, $Search)
EndFunc

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

Please note haven't tested this but it should work, at the top of your script add something like:

Global $Search = -1

In your _Search() function use:

$Search = _GUICtrlListView_FindText($ListView1, Guictrlread($Input1), $Search)

This should now iterate through each search starting at the last Search index

You should probably Add a button "New Search" or a "Reset" button to reset the $Search back to -1 when searching for something different.

Hopefully that makes sense.

1 person likes this

Share this post


Link to post
Share on other sites

#3 ·  Posted

Instead of searching through the text store all of the data from the listview in an array and populate the listview with the array. Then you just search for the array, not the listview. This will help with the performance since it doesn't have to access the listview data and instead will use the array. It's not a huge deal when you're only dealing with a few hundred items but when you get into the thousands, trying to use _FindText is going to be noticeably slow.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <Guilistview.au3>

Global $aDatabase[0]

For $i = 1 to 30
    _ArrayAdd($aDatabase, "Name" & $i)
Next

$Form1 = GUICreate("Form1", 615, 352, 192, 124)
$ListView1 = GUICtrlCreateListView("Names", 0, 40, 610, 310)
$Input1 = GUICtrlCreateInput("", 224, 8, 177, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$Button1 = GUICtrlCreateButton("Search", 409, 8, 111, 25)
GUISetState(@SW_SHOW)

_GUICtrlListView_SetColumnWidth($ListView1,0,200)

_Load()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            _Search(GUICtrlRead($Input1))
    EndSwitch
WEnd

Func _Load()
    For $i = 0 to UBound($aDatabase) - 1
        _GUICtrlListView_AddItem($ListView1, $aDatabase[$i])
    Next
EndFunc

Func _Search($sValue)
    If ($sValue = "") Then Return
    For $i = 0 to UBound($aDatabase) - 1
        If ($aDatabase[$i] = $sValue) Then
            ; $i + 1 because the array is 0 based but the listview rows are 1 based
            ConsoleWrite("Found '" & $sValue & "' on row & " & ($i + 1) & @LF)
        EndIf
    Next
EndFunc

 

1 person likes this

Share this post


Link to post
Share on other sites

#4 ·  Posted

Thanks subz your way works <3
also thank you inuno

Share this post


Link to post
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