Search the Community
Showing results for tags 'treeview array'.
-
For those who use TreeViews and wish to call a Function to grab the contents of the TreeView into a 1D array, then _GUICtrlTreeView_CreateArray() is for you. It will Return an array with the contents of the TreeView inc. the number of rows. Simply run the Example to get an idea of the output. Thanks. Function: ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GUICtrlTreeView_CreateArray ; Description ...: Creates a 1-dimensional array from a TreeView. ; Syntax ........: _GUICtrlTreeView_CreateArray($hTreeView) ; Parameters ....: $hTreeView - Control ID/Handle to the control ; Return values .: Success - The array returned is one-dimensional and is made up of the following: ; $aArray[0] = Number of rows ; $aArray[1] = 1st row ; $aArray[2] = 2nd row ; $aArray[n] = nth row ; Failure - Sets @error to non-zero and returns an empty an array. ; Author ........: guinness ; Remarks .......: GUICtrlTreeView.au3 should be included. ; Example .......: Yes ; =============================================================================================================================== Func _GUICtrlTreeView_CreateArray($hTreeView) Local $iItemCount = _GUICtrlTreeView_GetCount($hTreeView) Local $aReturn[$iItemCount + 1] = [$iItemCount] Local $hItem = _GUICtrlTreeView_GetFirstItem($hTreeView) If $iItemCount And $hItem Then $aReturn[1] = _GUICtrlTreeView_GetText($hTreeView, $hItem) For $i = 2 To $iItemCount $hItem = _GUICtrlTreeView_GetNext($hTreeView, $hItem) $aReturn[$i] = _GUICtrlTreeView_GetText($hTreeView, $hItem) Next EndIf Return SetError(Int($aReturn[0] = 0), 0, $aReturn) EndFunc ;==>_GUICtrlTreeView_CreateArrayExample use of Function: #include <Array.au3> ; Required only for _ArrayDisplay(). #include <Constants.au3> #include <GUITreeView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example() Func Example() Local $iWidth = 600, $iHeight = 400, $iTreeView = 0 Local $hGUI = GUICreate('_GUICtrlTreeView_CreateArray()', $iWidth, $iHeight, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX)) _CreateTreeView($hGUI, $iTreeView) Local $iGetArray = GUICtrlCreateButton('Get Array', $iWidth - 90, $iHeight - 28, 85, 25) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKSIZE + $GUI_DOCKBOTTOM) Local $iRefresh = GUICtrlCreateButton('Refresh', $iWidth - 180, $iHeight - 28, 85, 25) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKSIZE + $GUI_DOCKBOTTOM) GUISetState(@SW_SHOW, $hGUI) Local $aReturn = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iGetArray $aReturn = _GUICtrlTreeView_CreateArray($iTreeView) _ArrayDisplay($aReturn, '_GUICtrlTreeView_CreateArray() array.') Case $iRefresh _CreateTreeView($hGUI, $iTreeView) EndSwitch WEnd GUIDelete($hGUI) Return True EndFunc ;==>Example Func _CreateTreeView($hGUI, ByRef $iTreeView) Local $aClientSize = WinGetClientSize($hGUI) If @error = 0 Then If $iTreeView Then GUICtrlDelete($iTreeView) EndIf $iTreeView = GUICtrlCreateTreeView(0, 0, $aClientSize[0], $aClientSize[1] - 30) GUICtrlSetResizing($iTreeView, $GUI_DOCKBORDERS) __TreeViewFill($iTreeView, Random(25, 100, 1), Random(2, 5, 1)) ; Fill the TreeView with Random data. EndIf EndFunc ;==>_CreateTreeView Func __TreeViewFill($hTreeView, $iItems, $iChildItems) ; Required only for the Example. If Not IsHWnd($hTreeView) Then $hTreeView = GUICtrlGetHandle($hTreeView) EndIf Local $fIsCheckboxesStyle = (BitAND(_WinAPI_GetWindowLong($hTreeView, $GWL_STYLE), $TVS_CHECKBOXES) = $TVS_CHECKBOXES), $hChildItem, $hItem _GUICtrlTreeView_BeginUpdate($hTreeView) For $i = 1 To $iItems $hItem = _GUICtrlTreeView_Add($hTreeView, 0, 'Item ' & $i) For $j = 1 To $iChildItems $hChildItem = _GUICtrlTreeView_AddChild($hTreeView, $hItem, 'Child Item ' & $j) If Random(0, 1, 1) And $fIsCheckboxesStyle Then _GUICtrlTreeView_SetChecked($hTreeView, $hChildItem, True) EndIf Next If Random(0, 1, 1) And $fIsCheckboxesStyle Then _GUICtrlTreeView_SetChecked($hTreeView, $hItem, True) EndIf Next _GUICtrlTreeView_EndUpdate($hTreeView) EndFunc ;==>__TreeViewFill