behdadsoft Posted June 6, 2018 Share Posted June 6, 2018 (edited) Hi. I have this code that have a TreeView object with many parent and child. I want when write something into inputbox, compare input text with all child and if result is true show me matches child with input text. but i don't know why it don't work correctly and don't show me all matches child. expandcollapse popup#RequireAdmin #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <GuiTreeView.au3> #include <Array.au3> #include <File.au3> local Const $Path = @ScriptDir Dim $Parent[1] Dim $Child[10] local $Count = 0 Global Const $SourcesPath = @ScriptDir ;Create GUI local $GUI = GUICreate("TreeView") GUISetState(@SW_SHOW) ; Create InputBox local $Input = GUICtrlCreateInput("",100,25) Local $idInputChange = GUICtrlCreateDummy() ; Crete TreeViewObject local $TreeObject = GUICtrlCreateTreeView(100,70,200,250) Local $hTreeObject = GUICtrlGetHandle($TreeObject) ;Get Folder name to Array $GetFolderList = _FileListToArray($SourcesPath,"*",$FLTA_FOLDERS) ;Redim $TreeParent UBound ReDim $Parent[UBound($GetFolderList)] ;Get SubFolders and Add Child to Tree View Item Local $iStart = GUICtrlCreateDummy() for $a = 1 to UBound($Parent) - 1 $Parent[$a] = GUICtrlCreateTreeViewItem($GetFolderList[$a],$TreeObject) $RecordChildFolder = _FileListToArrayRec($SourcesPath & $GetFolderList[$a],"*",$FLTAR_FOLDERS,$FLTAR_NORECUR,$FLTAR_SORT) for $b = 1 to UBound($RecordChildFolder) - 1 $Child[$b] = GUICtrlCreateTreeViewItem($RecordChildFolder[$b] ,$Parent[$a]) Next Next Local $iEnd = GUICtrlCreateDummy() ConsoleWrite( "Search for 0 - 14" & @CRLF & @CRLF ) GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") while 1 Switch GUIGetMsg() ; Search in InputBox Case $idInputChange _Search() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($GUI) Func _Search() $InputText = GUICtrlRead($Input) ;Local $sParent[10], $aMatches[10], $iMatches = 0, $sMatchChild[10] if $InputText <> "" Then for $i = 0 to UBound($Child) - 1 if StringInStr(GUICtrlRead($Child[$i],1), $InputText) <> 0 Then MsgBox(0,"",GUICtrlRead($Child[$i],1)) EndIf Next EndIf EndFunc Func MY_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $iIDFrom = BitAND($wParam, 0xFFFF) ; LoWord - this gives the control which sent the message Local $iCode = BitShift($wParam, 16) ; HiWord - this gives the message that was sent If $iCode = $EN_CHANGE Then ; If we have the correct message Switch $iIDFrom ; See if it comes from one of the inputs Case $Input GUICtrlSendToDummy( $idInputChange ) EndSwitch EndIf EndFunc ;==>MY_WM_COMMAND dose anyone know why do this happen? Edited June 7, 2018 by behdadsoft Link to comment Share on other sites More sharing options...
LarsJ Posted June 6, 2018 Share Posted June 6, 2018 (edited) Because the child items in $Child array are overwritten all the time: ;Get SubFolders and Add Child to Tree View Item Local $iStart = GUICtrlCreateDummy() for $a = 1 to UBound($Parent) - 1 $Parent[$a] = GUICtrlCreateTreeViewItem($GetFolderList[$a],$TreeObject) $RecordChildFolder = _FileListToArrayRec($SourcesPath & $GetFolderList[$a],"*",$FLTAR_FOLDERS,$FLTAR_NORECUR,$FLTAR_SORT) for $b = 1 to UBound($RecordChildFolder) - 1 $Child[$b] = GUICtrlCreateTreeViewItem($RecordChildFolder[$b] ,$Parent[$a]) Next Next Since you start with $b = 1 for each $a-loop all previous childs are overwritten: for $b = 1 to UBound($RecordChildFolder) - 1 $Child[$b] = GUICtrlCreateTreeViewItem($RecordChildFolder[$b] ,$Parent[$a]) Next There was a reason why I changed this part of the code. Edited June 6, 2018 by LarsJ Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 6, 2018 Moderators Share Posted June 6, 2018 behdadsoft, You are constantly reusing the same $Child array to list the contents of each folder - so you only ever end up with the final folder contents in that array. Not surprising that you do not find the contents of the other folders. You also limit this array to 10 elements - what happens if there are more than 10 folders within a folder? You need to store all of the child ControlIDs - like this: expandcollapse popup;#RequireAdmin #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <GuiTreeView.au3> #include <Array.au3> #include <File.au3> ;Local $Count = 0 ; What is this for? <<<<<<<<<<<<<<<<<<<<<< Global Const $SourcesPath = @ScriptDir ;Create GUI Local $GUI = GUICreate("TreeView") ; Create InputBox Local $Input = GUICtrlCreateInput("", 100, 25) Local $idInputChange = GUICtrlCreateDummy() ; Crete TreeView Local $TreeObject = GUICtrlCreateTreeView(100, 70, 200, 250) Local $hTreeObject = GUICtrlGetHandle($TreeObject) ;Get Folder name to Array $GetFolderList = _FileListToArray($SourcesPath, "*", $FLTA_FOLDERS) ;Create parent and child folders - child is a 2D array to hold all the child ControlIDs <<<<<<<<<<<<<<<<<<< Local $Parent[UBound($GetFolderList)] Local $Child[UBound($GetFolderList)][1] ;Get SubFolders and Add Child to Tree View Item ;Local $iStart = GUICtrlCreateDummy() : Why are you doing this? <<<<<<<<<<<<<<<<<<< For $a = 1 To UBound($Parent) - 1 $Parent[$a] = GUICtrlCreateTreeViewItem($GetFolderList[$a], $TreeObject) ; Note you need to add the "\" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $RecordChildFolder = _FileListToArrayRec($SourcesPath & "\" & $GetFolderList[$a], "*", $FLTAR_FOLDERS, $FLTAR_NORECUR, $FLTAR_SORT) ; if folders were found <<<<<<<<<<<<<<<<<<<<<<< If Not @error Then ; Adjust the size of the child array to fit <<<<<<<<<<<<<<<<<<<<<<<<< If $RecordChildFolder[0] > UBound($Child, 2) - 1 Then ReDim $Child[UBound($GetFolderList)][$RecordChildFolder[0] + 1] EndIf For $b = 1 To UBound($RecordChildFolder) - 1 $Child[$a][$b] = GUICtrlCreateTreeViewItem($RecordChildFolder[$b], $Parent[$a]) Next EndIf Next ;Local $iEnd = GUICtrlCreateDummy() GUISetState() ConsoleWrite("Search for 0 - 14" & @CRLF & @CRLF) GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") While 1 Switch GUIGetMsg() ; Search in InputBox Case $idInputChange _Search() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($GUI) Func _Search() $InputText = GUICtrlRead($Input) If $InputText <> "" Then ; Now look through the 2D array to find matches For $i = 0 To UBound($Child) - 1 For $j = 0 To UBound($Child, 2) - 1 $TreeItemText = GUICtrlRead($Child[$i][$j], 1) If StringInStr($TreeItemText, $InputText) <> 0 Then MsgBox(0, "", $TreeItemText) EndIf Next Next EndIf EndFunc ;==>_Search Func MY_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $iIDFrom = BitAND($wParam, 0xFFFF) ; LoWord - this gives the control which sent the message Local $iCode = BitShift($wParam, 16) ; HiWord - this gives the message that was sent If $iCode = $EN_CHANGE Then ; If we have the correct message Switch $iIDFrom ; See if it comes from one of the inputs Case $Input GUICtrlSendToDummy($idInputChange) EndSwitch EndIf EndFunc ;==>MY_WM_COMMAND That works fine for me. M23 behdadsoft 1 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...
behdadsoft Posted June 6, 2018 Author Share Posted June 6, 2018 (edited) is your mean this part? ;Get SubFolders and Add Child to Tree View Item Local $iStart = GUICtrlCreateDummy() for $a = 1 to UBound($TreeParent) - 1 $TreeParent[$a] = GUICtrlCreateTreeViewItem("Parent " & $a,$TreeObject) for $b = 0 to UBound($TreeChild) / 2 - 1 $TreeChild[$iChilds] = GUICtrlCreateTreeViewItem("Child " & $iChilds ,$TreeParent[$a]) $iChilds += 1 Next Next Local $iEnd = GUICtrlCreateDummy() This piece of code don't work with my above code (First post). Edited June 6, 2018 by Melba23 Quote removed Link to comment Share on other sites More sharing options...
behdadsoft Posted June 6, 2018 Author Share Posted June 6, 2018 (edited) Thanks Melba23. It work Great. Is there any way to do this with 1D Array? Edited June 6, 2018 by Melba23 Quote removed Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 6, 2018 Moderators Share Posted June 6, 2018 behdadsoft, If it works as it is, why do you need to rewrite it to use a 1D array? 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...
behdadsoft Posted June 6, 2018 Author Share Posted June 6, 2018 (edited) because i used $Child in 1D in throughout of my code and i should change many lines. Edited June 6, 2018 by Melba23 Quote removed Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 6, 2018 Moderators Share Posted June 6, 2018 behadsoft, Only a little different: expandcollapse popup;#RequireAdmin #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <GuiTreeView.au3> #include <Array.au3> #include <File.au3> Local $Count = 0 ; Now you need this <<<<<<<<<<<<<<<<<<<<<< Global Const $SourcesPath = @ScriptDir ;Create GUI Local $GUI = GUICreate("TreeView") ; Create InputBox Local $Input = GUICtrlCreateInput("", 100, 25) Local $idInputChange = GUICtrlCreateDummy() ; Crete TreeView Local $TreeObject = GUICtrlCreateTreeView(100, 70, 200, 250) Local $hTreeObject = GUICtrlGetHandle($TreeObject) ;Get Folder name to Array $GetFolderList = _FileListToArray($SourcesPath, "*", $FLTA_FOLDERS) ;Create parent and child folders - child is a 1D array to hold all the child ControlIDs <<<<<<<<<<<<<<<<<<< Local $Parent[UBound($GetFolderList)] Local $Child[1] ;Get SubFolders and Add Child to Tree View Item For $a = 1 To UBound($Parent) - 1 $Parent[$a] = GUICtrlCreateTreeViewItem($GetFolderList[$a], $TreeObject) ; Note you need to add the "\" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $RecordChildFolder = _FileListToArrayRec($SourcesPath & "\" & $GetFolderList[$a], "*", $FLTAR_FOLDERS, $FLTAR_NORECUR, $FLTAR_SORT) ; if folders were found <<<<<<<<<<<<<<<<<<<<<<< If Not @error Then ; Adjust the size of the child array to fit the new children <<<<<<<<<<<<<<<<<<<<<<<<< ReDim $Child[UBound($Child) + $RecordChildFolder[0]] For $b = 1 To UBound($RecordChildFolder) - 1 ; Increase count to get next insertion point $Count += 1 $Child[$Count] = GUICtrlCreateTreeViewItem($RecordChildFolder[$b], $Parent[$a]) Next EndIf Next ;Local $iEnd = GUICtrlCreateDummy() GUISetState() ConsoleWrite("Search for 0 - 14" & @CRLF & @CRLF) GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") While 1 Switch GUIGetMsg() ; Search in InputBox Case $idInputChange _Search() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($GUI) Func _Search() $InputText = GUICtrlRead($Input) If $InputText <> "" Then ; Now look through the 2D array to find matches For $i = 1 To UBound($Child) - 1 $TreeItemText = GUICtrlRead($Child[$i], 1) If StringInStr($TreeItemText, $InputText) <> 0 Then MsgBox(0, "", $TreeItemText) EndIf Next EndIf EndFunc ;==>_Search Func MY_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $iIDFrom = BitAND($wParam, 0xFFFF) ; LoWord - this gives the control which sent the message Local $iCode = BitShift($wParam, 16) ; HiWord - this gives the message that was sent If $iCode = $EN_CHANGE Then ; If we have the correct message Switch $iIDFrom ; See if it comes from one of the inputs Case $Input GUICtrlSendToDummy($idInputChange) EndSwitch EndIf EndFunc ;==>MY_WM_COMMAND And please when you reply in future, use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - responders know what they wrote and it just pads the thread unnecessarily. Thanks in advance for your cooperation. M23 behdadsoft 1 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...
behdadsoft Posted June 6, 2018 Author Share Posted June 6, 2018 Thanks Melba23. Work great. 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