Search the Community
Showing results for tags 'listbox array'.
-
For those who use ListBoxes and wish to call a Function to grab the contents of the ListBox into a 1D array, then _GUICtrlListBox_CreateArray() is for you. It will Return an array with the contents of the ListBox inc. the number of rows. Simply run the Example to get an idea of the output. Thanks. Function: ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GUICtrlListBox_CreateArray ; Description ...: Creates a 1-dimensional array from a listbox. ; Syntax ........: _GUICtrlListBox_CreateArray($hListBox) ; Parameters ....: $hListBox - 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 ; Author ........: guinness ; Remarks .......: GUICtrlListBox.au3 should be included. ; Example .......: Yes ; =============================================================================================================================== Func _GUICtrlListBox_CreateArray($hListBox) Local $iItemCount = _GUICtrlListBox_GetCount($hListBox) Local $aReturn[$iItemCount + 1] = [$iItemCount] For $i = 0 To $iItemCount - 1 $aReturn[$i + 1] = _GUICtrlListBox_GetText($hListBox, $i) Next Return SetError(Number($aReturn[0] = 0), 0, $aReturn) EndFunc ;==>_GUICtrlListBox_CreateArrayExample use of Function: #include <Array.au3> ; Required only for _ArrayDisplay(). #include <GUIListBox.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example() Func Example() Local $iWidth = 600, $iHeight = 400, $iListBox = 0 Local $hGUI = GUICreate('_GUICtrlListBox_CreateArray()', $iWidth, $iHeight, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX)) _CreateListBox($hGUI, $iListBox) 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 = _GUICtrlListBox_CreateArray($iListBox) _ArrayDisplay($aReturn, '_GUICtrlListBox_CreateArray() array.') Case $iRefresh GUICtrlDelete($iListBox) _CreateListBox($hGUI, $iListBox) EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>Example Func _CreateListBox($hGUI, ByRef $iListBox) Local $aClientSize = WinGetClientSize($hGUI) $iListBox = GUICtrlCreateList('', 0, 0, $aClientSize[0], $aClientSize[1] - 30) GUICtrlSetResizing($iListBox, $GUI_DOCKBORDERS) Sleep(250) __ListBoxFill($iListBox, Random(25, 100, 1)) ; Fill the ListBox with Random data. EndFunc ;==>_CreateListBox Func __ListBoxFill($hListBox, $iRows) ; Required only for the Example. If Not IsHWnd($hListBox) Then $hListBox = GUICtrlGetHandle($hListBox) EndIf _GUICtrlListBox_BeginUpdate($hListBox) For $i = 0 To $iRows - 1 _GUICtrlListBox_AddString($hListBox, 'Row ' & $i + 1) Next _GUICtrlListBox_EndUpdate($hListBox) EndFunc ;==>__ListBoxFill