Advertisement
Guest User

example_2

a guest
Oct 24th, 2012
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 3.23 KB | None | 0 0
  1. #include <GUIConstantsEx.au3>
  2. #include <ListViewConstants.au3>
  3. #include <WindowsConstants.au3>
  4. ;ADD;
  5. #include <GuiListView.au3>
  6. #include <Array.au3>
  7. ;----
  8. Opt("GUIDataSeparatorChar", "/")
  9. $GUI = GUICreate("Form1", 673, 433, -1, -1)
  10. $hListView = GUICtrlCreateListView("Name File / Value", 8, 64, 657, 361)
  11. GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 380)
  12. GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 270)
  13. $Button1 = GUICtrlCreateButton("Load", 8, 16, 105, 33)
  14. $Input1 = GUICtrlCreateInput("Input1", 136, 24, 145, 21)
  15. $Button2 = GUICtrlCreateButton("Search", 304, 16, 105, 33)
  16. GUISetState(@SW_SHOW)
  17. While 1
  18.     $nMsg = GUIGetMsg()
  19.     Switch $nMsg
  20.     Case $GUI_EVENT_CLOSE
  21.     Exit
  22.     Case $Button1
  23.         $Log = "Test1/Test" & @LF & "Test2/Sun" & @LF & "Sun1/Sun/" & @LF & "Earth1/Earth1"
  24.         $aArray = StringSplit($Log, @LF)
  25.         For $i = 1 To $aArray[0]
  26.             GUICtrlCreateListViewItem($aArray[$i], $hListView)
  27.         Next
  28.     ;ADD
  29.     Case $Button2
  30.         $search = _GuiCtrlListView_ItemSearch($hListView,GUICtrlRead($Input1))
  31.         _ArrayDisplay($search)
  32.     ;--
  33.     EndSwitch
  34. WEnd
  35.  
  36.  
  37.  
  38. ; #FUNCTION# ====================================================================================================================
  39. ; Name ..........: _GuiCtrlListView_ItemSearch
  40. ; Description ...: Search a text in a listview
  41. ; Syntax ........: _GuiCtrlListView_ItemSearch($ctrlId, $sSearch[, $sCaseSense = False])
  42. ; Parameters ....: $ctrlId              - Control ID from listview.
  43. ;                  $sSearch             - String to search.
  44. ;                  $sCaseSense          - [optional] If function use case sensitive or not.
  45. ;                       > 0 - not case sensitive
  46. ;                       > 1 - case sensitive
  47. ; Return values .: Succes:
  48. ;                   > $Array[0][0] = Number of match string.
  49. ;                   > $Array[1][0] = Line of result 1 (zero based)
  50. ;                       > $Array[1][1] = SubItem of result 1 (zero based)
  51. ;                   >.....................................................
  52. ;                   > $Array[n][0] = Line of result 1 (zero based)
  53. ;                       > $Array[n][1] = SubItem of result 1 (zero based)
  54. ;                  Fail :
  55. ;                   > No string find return $Array[0][0] > 0
  56. ;                   > @error
  57. ;                       -> 1 : $sSearch is empty ("")
  58. ;                       -> 2 : List had no lines (or control id is not a list)
  59. ;                       -> 3 : List had no column (or control id is not a list)
  60. ; Author ........: PlayHD (Ababei Andrei)
  61. ; Modified ......: -
  62. ; Remarks .......: -
  63. ; Related .......: _GUICtrlListView_GetItemText
  64. ; Link ..........: -
  65. ; Example .......: No
  66. ; ===============================================================================================================================
  67. Func _GuiCtrlListView_ItemSearch($ctrlId,$sSearch, $sCaseSense = 0)
  68.     If $sSearch = "" Then Return SetError(1,0,-2)
  69.     Local $iCount = _GUICtrlListView_GetItemCount($ctrlId)
  70.     If $iCount <= 0 Then Return SetError(2,0,-2)
  71.     Local $iCol = _GUICtrlListView_GetColumnCount($ctrlId)
  72.     If $iCol <= 0 Then Return SetError(3,0,-2)
  73.     Local $i, $j,$k = 1, $rArray[1][1]
  74.     $rArray[0][0] = 0
  75.     For $i = 0 To $iCount
  76.         For $j = 0 To $iCol
  77.             If StringInStr (_GUICtrlListView_GetItemText($ctrlId,$i,$j),$sSearch,$sCaseSense) <> 0 Then
  78.                 ReDim $rArray[$k+1][2]
  79.                 $rArray[0][0] += 1
  80.                 $rArray[$k][0] = $i
  81.                 $rArray[$k][1] = $j
  82.                 $k += 1
  83.             EndIf
  84.         Next
  85.     Next
  86.     Return $rArray
  87. EndFunc ;==> _GuiCtrlListView_ItemSearch
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement