Jump to content

Searching a listview


Recommended Posts

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

@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()

Link to comment
Share on other sites

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

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