Jump to content
Sign in to follow this  
motionman95

Searching a listview

Recommended Posts

motionman95

Hello!

I'm trying to read a listview for items that match my search criteria. Of course, there's the _GUICtrlListView_FindInText and other function the help with this problem. The only problem is that I wish to return all the items that match my criteria, and not just the first one the function comes to. I came up with this, but its fault is the fact that it shows some results more than once:

Func searchWindows()
    $itemNum = _GUICtrlListView_FindInText(GUICtrlGetHandle($WinListView), GUICtrlRead($Search_Box))
    $i = 0
    
    While $itemNum > -1 AND $i < _GUICtrlListView_GetItemCount($WinListView)
        $itemNum = _GUICtrlListView_FindInText(GUICtrlGetHandle($WinListView), GUICtrlRead($Search_Box), $itemNum)
        ConsoleWrite($itemNum & " Text: " & _GUICtrlListView_GetItemText($WinListView, $itemNum, 1) & @CRLF)
        $i += 1
    WEnd
EndFunc  ;==>searchWindows

Thanks in advance,

I can't wait to see your responses!


Share this post


Link to post
Share on other sites
Zinthose

I haven't tested it but...

Func searchWindows()
    Local $itemNum = -1
    
    While True
        $itemNum = _GUICtrlListView_FindInText(GUICtrlGetHandle($WinListView), GUICtrlRead($Search_Box), $itemNum)
        If $itemNum = -1 Then ExitLoop
        ConsoleWrite($itemNum & " Text: " & _GUICtrlListView_GetItemText($WinListView, $itemNum, 1) & @CRLF)
    WEnd
EndFunc  ;==>searchWindows

The "_GUICtrlListView_FindInText" function has a the $iStart param to specify a search start location. ^_^


--- TTFN

Share this post


Link to post
Share on other sites
BrettF
motionman95

@Zinthose:

Your code doesn't work. Is just loops and displays the same lines over and over again.

Off topic:

Did you happen to get your username from Raven?

@BrettF: _GUICtrlListView_AddItem() and _GUICtrlListView_AddSubItem()


Share this post


Link to post
Share on other sites
Zinthose

Ok, I found the problem.. I needed to disable the wrap feature. /doh

#include 'ButtonConstants.au3'
#include 'EditConstants.au3'
#include 'GUIConstantsEx.au3'
#include 'ListViewConstants.au3'
#include 'WindowsConstants.au3'
#include 'GuiListView.au3'

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 625, 445, -999, 144)
$WinListView = GUICtrlCreateListView("", 0, 0, 624, 409)
$Search_Box = GUICtrlCreateInput("Col 2", 0, 408, 505, 21)
$Search = GUICtrlCreateButton("Search", 504, 408, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

    _GUICtrlListView_InsertColumn($WinListView, 0, "Column 1", 100)
    _GUICtrlListView_InsertColumn($WinListView, 1, "Column 2", 100)
    _GUICtrlListView_InsertColumn($WinListView, 2, "Column 3", 100)

    _GUICtrlListView_AddItem($WinListView, "Row 1: Col 1", 0)
    _GUICtrlListView_AddSubItem($WinListView, 0, "Row 1: Col 2", 1, 1)
    _GUICtrlListView_AddSubItem($WinListView, 0, "Row 1: Col 3", 2, 2)
    _GUICtrlListView_AddItem($WinListView, "Row 2: Col 1", 1)
    _GUICtrlListView_AddSubItem($WinListView, 1, "Row 2: Col 2", 1, 2)
    _GUICtrlListView_AddItem($WinListView, "Row 3: Col 1", 2)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Search
            searchWindows()
    EndSwitch
WEnd



Func searchWindows()
    Local $itemNum = -1
   
    While True
        $itemNum = _GUICtrlListView_FindInText(GUICtrlGetHandle($WinListView), GUICtrlRead($Search_Box), $itemNum, False)
        If @error or $itemNum = -1 Then ExitLoop
        
        ConsoleWrite($itemNum & " Text: " & _GUICtrlListView_GetItemText($WinListView, $itemNum, 1) & @CRLF)
    WEnd
EndFunc  ;==>searchWindows

p.s. Yes, Raven's little chant is the source of my name ^_^

Edited by Zinthose

--- TTFN

Share this post


Link to post
Share on other sites
motionman95

@Zinthose: It doesn't work whether I leave the +1 there or not. =(


Share this post


Link to post
Share on other sites
BrettF
Zinthose

I fixed it... see last edited post


--- TTFN

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.