StungStang Posted March 12, 2012 Share Posted March 12, 2012 (edited) 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 March 12, 2012 by StungStang Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 12, 2012 Moderators Share Posted March 12, 2012 StungStang, You need to use the $iStart parameter to keep searching after finding the first match: expandcollapse popup#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? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now