Jump to content

_GUICtrlListView_FindText question


Recommended Posts

Hi to all, i want to know if in the all listview item, there is an item contenent a certain text. I see _GUICtrlListView_FindText but it give me only The zero based index of the first item, but if there are multiple item that match the criteria?

For example i've this script:

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
$Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work
_Main()
Func _Main()
Local $iI, $hListView
GUICreate("ListView Find In Text", 400, 300)
$hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
GUISetState()
; Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "Items", 100)
; Add items
_GUICtrlListView_BeginUpdate($hListView)
For $iI = 1 To 49
  _GUICtrlListView_AddItem($hListView, "Item " & $iI)
Next
_GUICtrlListView_AddItem($hListView, "Target item") ;<====first item
For $iI = 51 To 100
  _GUICtrlListView_AddItem($hListView, "Item " & $iI)
Next
_GUICtrlListView_AddItem($hListView, "Targetttt item") <====second item

_GUICtrlListView_EndUpdate($hListView)

; Search for target item
$iI = _GUICtrlListView_FindText($hListView, "tArGeT",True,True)
MsgBox(4160, "Information", "Target Item Index: " & $iI)
_GUICtrlListView_EnsureVisible($hListView, $iI); Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc   ;==>_Main

There is a way to getting _GUICtrlListView_FindText if there are more than one item that match the search criteria? If not a fast way to do that?

Hi!

Edited by StungStang
Link to post
Share on other sites
  • Moderators

StungStang,

You need to use the $iStart parameter to keep searching after finding the first match: :bye:

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

_Main()

Func _Main()

    Local $iI, $hListView

    GUICreate("ListView Find In Text", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    GUISetState()

    ; Add columns
    _GUICtrlListView_InsertColumn($hListView, 0, "Items", 100)

    ; Add items
    _GUICtrlListView_BeginUpdate($hListView)
    For $i = 0 To 49
        _GUICtrlListView_AddItem($hListView, "Item " & $i)
    Next
    _GUICtrlListView_AddItem($hListView, "Target item") ;<====first item
    For $i = 51 To 99
        _GUICtrlListView_AddItem($hListView, "Item " & $i)
    Next
    _GUICtrlListView_AddItem($hListView, "Targetttt item") ;<= == =second item
    For $i = 101 To 150
        _GUICtrlListView_AddItem($hListView, "Item " & $i)
    Next

    _GUICtrlListView_EndUpdate($hListView)

    ; Search for target items
    $sTarget_List = ""
    $iI = -2
    ; Keep running through ListView to find all matching items
    While 1
        $iI = _GUICtrlListView_FindText($hListView, "tArGeT", $iI + 1, True, False) ; Note $iI + 1 to start at next item
        ConsoleWrite($iI & @CRLF)
        If $iI = -1 Then
            ExitLoop ; Nothing found
        Else
            $sTarget_List &= $iI & "|" ; Add to list
        EndIf
    WEnd

    ; Convert list to array
    $aTarget = StringSplit($sTarget_List, "|")
    _ArrayDisplay($aTarget, "All found")

    ; Show all items
    For $i = 1 To $aTarget[0] - 1
        _GUICtrlListView_EnsureVisible($hListView, Number($aTarget[$i]))
        Sleep(1000)
    Next

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    GUIDelete()

EndFunc   ;==>_Main

All clear? :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...