ZwinnyRolnik Posted July 24, 2010 Share Posted July 24, 2010 I have script for searching items in listview but if item or subitem = 0 then script does not work. Anyone know why and can help me? Just test, click search next, next next (w8 for subitem or item = 0) and then click x times back... Pls help. expandcollapse popup#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("", 625, 445, 99, 144) $ListView = GUICtrlCreateListView("", 0, 0, 624, 409) $szukana = GUICtrlCreateInput("15", 10, 415, 55, 21) $Search2 = GUICtrlCreateButton("Search(click first)", 504, 415, 120, 25, 0) $Search3 = GUICtrlCreateButton("next", 150, 415, 75, 25, 0) $cofnij = GUICtrlCreateButton("back", 250, 415, 75, 25, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### For $i = 0 To 31 _GUICtrlListView_AddColumn($ListView, "teksty"&$i, "",2) _GUICtrlListView_SetColumnWidth($ListView, $i, 150) Next For $i = 1 To 70 _GUICtrlListView_AddItem($ListView, random(1,150,1)) Next For $i = 1 To 70 For $j = 1 To 80 _GUICtrlListView_AddSubItem($ListView, $i - 1, random(1,150,1), $j) Next Next While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Search2 Global $zapamietaji[_GUICtrlListView_GetItemCount($ListView)] Global $zapamietajj[_GUICtrlListView_GetColumnCount($ListView)] Global $pamiec[1001] searchWindows() Case $search3 searchWindows() Case $cofnij Global $gogo = True cofnij() searchWindows() EndSwitch WEnd Func searchWindows() For $I = 0 To _GUICtrlListView_GetItemCount($ListView) - 1 for $j = 0 to _GUICtrlListView_GetColumnCount($ListView) - 1 if $zapamietaji[$i] = $i And $zapamietajj[$j] = $j then ContinueLoop $Search = _GUICtrlListView_GetItemText($ListView, $I, $j) If $Search = guictrlread($szukana) Then _GUICtrlListView_EnsureVisibleEx($ListView, $i, $j) _GUICtrlListView_SetItemSelected($ListView, $i) _GUICtrlListView_SetSelectedColumn($ListView, $j) $zapamietaji[$i] = $i $zapamietajj[$j] = $j For $z = 0 to 1000 if $pamiec[$z] = "" Then $pamiec[$z] = $zapamietaji[$i]&","&$zapamietajj[$j] ExitLoop Else EndIf Next $tyt = WinGetTitle($form1) if StringLen($tyt) > 65 then WinSetTitle($form1,"","") $tyt = WinGetTitle($form1) WinSetTitle($Form1,"",$tyt&" | "&$pamiec[$z]) return EndIf Next Next MsgBox(0,"Program","Brak wyników") EndFunc ;==>searchWindows func cofnij() For $I = _GUICtrlListView_GetItemCount($ListView) - 1 To 0 step -1 for $j = _GUICtrlListView_GetColumnCount($ListView) - 1 to 0 step -1 if $zapamietaji[$i] <> "" And $zapamietajj[$j] <> "" then for $z = 0 to 1000 if $pamiec[$z] = $zapamietaji[$i]&","&$zapamietajj[$j] Then $zapamietaji[$i] = "" $zapamietajj[$j] = "" $pamiec[$z]= "" if $gogo = True Then $gogo = False cofnij() endIf Return Else EndIf Next Else EndIf Next Next EndFunc Func _GUICtrlListView_EnsureVisibleEx($hwnd, $iIndex, $iSubItem = 0, $fPartialOK = False) ;funkey April 15, 2010 If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) _SendMessage($hWnd, $LVM_ENSUREVISIBLE, $iIndex, $fPartialOK) Local $aRect = _GUICtrlListView_GetItemRect($hWnd, $iSubItem) Local $iPixel For $i = 0 To $iSubItem-1 ; 2 means: show at second visible column $iPixel += _GUICtrlListView_GetColumnWidth($hWnd, $i) Next _GUICtrlListView_Scroll($hWnd, $iPixel + $aRect[0], 0) EndFunc sorry for chaos Link to comment Share on other sites More sharing options...
ZwinnyRolnik Posted July 24, 2010 Author Share Posted July 24, 2010 anyone? ;p Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 25, 2010 Moderators Share Posted July 25, 2010 (edited) ZwinnyRolnik, Why it's not working?Because of the the "chaos"! I have rewritten the whole thing and I think it works as you want now. You could still improve it a great deal if you wanted to make some major changes - a 2D array would remove the need for the StringSplit/Number lines, for example. expandcollapse popup#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("", 625, 445, 99, 144) $ListView = GUICtrlCreateListView("", 0, 0, 624, 409) GUICtrlSetBkColor(-1, 0xCCCCCC) $Input = GUICtrlCreateInput("15", 10, 415, 55, 21) $Search = GUICtrlCreateButton("Search(click first)", 150, 415, 120, 25) $Next = GUICtrlCreateButton("next", 300, 415, 75, 25) GUICtrlSetState(-1, $GUI_DISABLE) $Back = GUICtrlCreateButton("back", 400, 415, 75, 25) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### For $i = 0 To 3 _GUICtrlListView_AddColumn($ListView, "teksty" & $i, "", 2) _GUICtrlListView_SetColumnWidth($ListView, $i, 150) Next For $i = 1 To 10 _GUICtrlListView_AddItem($ListView, Random(1, 30, 1)) Next For $i = 1 To 10 For $j = 1 To 4 _GUICtrlListView_AddSubItem($ListView, $i - 1, Random(1, 30, 1), $j) Next Next GUICtrlSetState($Input, $GUI_FOCUS) Global $Remember_i[_GUICtrlListView_GetItemCount($ListView)] Global $Remember_j[_GUICtrlListView_GetColumnCount($ListView)] While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Search ; Clear title and memory array WinSetTitle($Form1, "", "") Global $memory[1001] = [0] ; Search from start of LV searchWindows(0, 0) Case $Next ; Where was the last find? We need to increase the column count $Split = StringSplit($memory[$memory[0]], ",") $iStart_i = Number($Split[1]) $iStart_j = Number($Split[2]) + 1 ; But check if we need to move to a new line If $iStart_j = _GUICtrlListView_GetColumnCount($ListView) - 1 Then $iStart_j = 0 $iStart_i += 1 EndIf ; Check if we were at the final item last time - if not start searching from from the next position along If $iStart_i < _GUICtrlListView_GetItemCount($ListView) Then ConsoleWrite("Next " & $iStart_i & " - " & $iStart_j & @CRLF) searchWindows($iStart_i, $iStart_j) EndIf Case $Back ; Move back through the memory array Back() EndSwitch WEnd Func searchWindows($Start_i, $Start_j) ; We are starting a new search $fStart = True For $i = 0 To _GUICtrlListView_GetItemCount($ListView) - 1 For $j = 0 To _GUICtrlListView_GetColumnCount($ListView) - 1 ; So set the values we want to start at If $fStart Then $i = $Start_i $j = $Start_j $fStart = False EndIf ; You use $Search here, thus overwriting the ControlID of the Search button <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $Text = _GUICtrlListView_GetItemText($ListView, $i, $j) ; Do we have a match? If $Text = GUICtrlRead($Input) Then ; Highlight element _GUICtrlListView_EnsureVisibleEx($ListView, $i, $j) _GUICtrlListView_SetItemSelected($ListView, $i) _GUICtrlListView_SetSelectedColumn($ListView, $j) ; Increase count of finds $memory[0] += 1 ; Save the coordinates $memory[$memory[0]] = $i & "," & $j ; Alter the window title Window_Title() ; ; Enable Next button GUICtrlSetState($Next, $GUI_ENABLE) Return EndIf Next Next ; We got to then end of the LV If $memory[0] = 0 Then MsgBox(0, "Program", "Nothing Found") Else MsgBox(0, "Program", "Nothing More Found") EndIf ; Disable the next button - there are no more to find! GUICtrlSetState($Next, $GUI_DISABLE) ; If there are zero or 1 element found, there is no need for a Next button either! If $memory[0] < 2 Then GUICtrlSetState($Back, $GUI_DISABLE) Else GUICtrlSetState($Back, $GUI_ENABLE) EndIf EndFunc ;==>searchWindows Func Back() ; Get the coordinates of the current selection $Split = StringSplit($memory[$memory[0]], ",") ; Empty the current memory element $memory[$memory[0]] = "" ; Reduce the memory count $memory[0] -= 1 ; If the memory array is now empty If $memory[0] = 0 Then ; Clear the title WinSetTitle($Form1, "", "") ; Reset teh buttons GUICtrlSetState($Search, $GUI_ENABLE) GUICtrlSetState($Next, $GUI_DISABLE) GUICtrlSetState($Back, $GUI_DISABLE) ; Clear the selection - this is why we need to get the coordinates of the current selection in the first line _GUICtrlListView_SetItemSelected($ListView, Number($Split[1]), False) _GUICtrlListView_SetSelectedColumn($ListView, -1) Return EndIf ; Get the coordinates of the previous (now current) selection $Split = StringSplit($memory[$memory[0]], ",") $i = Number($Split[1]) $j = Number($Split[2]) ; Show selection _GUICtrlListView_EnsureVisibleEx($ListView, $i, $j) _GUICtrlListView_SetItemSelected($ListView, $i) _GUICtrlListView_SetSelectedColumn($ListView, $j) ; We can now go forward again - so enable the button GUICtrlSetState($Next, $GUI_ENABLE) ; Alter the window Title Window_Title() EndFunc Func Window_Title() $tyt = "" ; Add matches from the last For $i = $memory[0] To 1 Step -1 $tyt = "|" & $memory[$i] & $tyt ; Stop if the total is too long If StringLen($tyt) > 65 Then ExitLoop Next ; Set the title WinSetTitle($Form1, "", $tyt) EndFunc Func _GUICtrlListView_EnsureVisibleEx($hwnd, $iIndex, $iSubItem = 0, $fPartialOK = False) ;funkey April 15, 2010 If Not IsHWnd($hwnd) Then $hwnd = GUICtrlGetHandle($hwnd) _SendMessage($hwnd, $LVM_ENSUREVISIBLE, $iIndex, $fPartialOK) Local $aRect = _GUICtrlListView_GetItemRect($hwnd, $iSubItem) Local $iPixel For $i = 0 To $iSubItem - 1 ; 2 means: show at second visible column $iPixel += _GUICtrlListView_GetColumnWidth($hwnd, $i) Next _GUICtrlListView_Scroll($hwnd, $iPixel + $aRect[0], 0) EndFunc ;==>_GUICtrlListView_EnsureVisibleEx By the way, please learn how to use Tidy (<Tools> menu or Ctrl-T)! M23 Edit: I forgot to mention that you used $Search as both the ControlId of the Search button AND the text from the element (look for the <<<<<<<<<<<<<<< line). Doing this overwrote the ControlId and rendered the button unuseable from that point on. Try to use unique variable names - it helps in the long run! Edited July 25, 2010 by Melba23 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...
ZwinnyRolnik Posted July 25, 2010 Author Share Posted July 25, 2010 Amazing, I saw that you answered, I knew that it will be a good script, thank you very much! 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