Sign in to follow this  
Followers 0
muncherw

Populating a combobox from an array [SOLVED]

7 posts in this topic

#1 ·  Posted (edited)

I want to populate a dropdown list with the names of folders in a certain directory. I can get the names easily enough.

CODE
#Include <File.au3>

#Include <Array.au3>

$FileList=_FileListToArray(@DesktopDir,"*.*", 2)

If @Error=1 Then

MsgBox (0,"","No Files\Folders Found.")

Exit

EndIf

_ArrayDisplay($FileList,"$FileList")

But when I go to populate the list it doesn't work.

CODE

$combo = GuiCtrlCreateCombo("Select a folder",30, 75, 220, 200)

GuiCtrlSetData($combo, $FileList)

Perhaps GuiCtrlSetData($combo, $FileList) should be something like GuiCtrlSetData($combo, $FileList[1]) but I don't really know how to get it to go through every value in the array.

I figure I could make a loop or something but how do I know when the array is done?

Edited by muncherw

Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try:

GuiCtrlSetData($combo, "|" & _ArrayToString($FileList))

edit: Forgot you need a | at the beginning to clear out any list entries.

Edited by zorphnog

Share this post


Link to post
Share on other sites

Quick example :)

#include <file.au3>
$array=_FileListToArray(@ScriptDir)

$hwnd=GUICreate("test",400,200)
$combo=GUICtrlCreateCombo("Select an item",10,10)
For $i=1 To Ubound($array)-1
    GUICtrlSetData($combo,$array[$i])
Next

GUISetState()

Do
    $msg=GUIGetMsg()
Until $msg=-3

>_<


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

I want to populate a dropdown list with the names of folders in a certain directory. I can get the names easily enough.

CODE
#Include <File.au3>

#Include <Array.au3>

$FileList=_FileListToArray(@DesktopDir,"*.*", 2)

If @Error=1 Then

MsgBox (0,"","No Files\Folders Found.")

Exit

EndIf

_ArrayDisplay($FileList,"$FileList")

But when I go to populate the list it doesn't work.

CODE

$combo = GuiCtrlCreateCombo("Select a folder",30, 75, 220, 200)

GuiCtrlSetData($combo, $FileList)

Perhaps GuiCtrlSetData($combo, $FileList) should be something like GuiCtrlSetData($combo, $FileList[1]) but I don't really know how to get it to go through every value in the array.

I figure I could make a loop or something but how do I know when the array is done?

Modified example from the help

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIComboBox.au3>
#include <GuiConstantsEx.au3>
#include <Constants.au3>

Opt('MustDeclareVars', 1)

$Debug_CB = False; Check ClassName being passed to ComboBox/ComboBoxEx functions, set to True and use a handle to another control to see it work

_Main()

Func _Main()
    Local $hCombo

   ; Create GUI
    GUICreate("ComboBox Add Dir", 400, 296)
    $hCombo = GUICtrlCreateCombo("", 2, 2, 396, 296)
    GUISetState()

   ; Add files
    _GUICtrlComboBox_BeginUpdate($hCombo)
   _GUICtrlComboBox_AddDir($hCombo, @DesktopDir & "\*",BitOr($DDL_DIRECTORY ,$DDL_EXCLUSIVE))
    _GUICtrlComboBox_EndUpdate($hCombo)

   ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc  ;==>_Main

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Try:

GuiCtrlSetData($combo, "|" & _ArrayToString($FileList))

edit: Forgot you need a | at the beginning to clear out any list entries.

Thanks everyone. Zorph's answer does what I need. Well it throws a number in the front of the list which I guess is how many elements of the array so I need to prune that. Which also answers my other question on how you know when the array is ended. I can't seem to keep array info in my head for very long without forgetting it.


Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]

Share this post


Link to post
Share on other sites

Thanks everyone. Zorph's answer does what I need. Well it throws a number in the front of the list which I guess is how many elements of the array so I need to prune that. Which also answers my other question on how you know when the array is ended. I can't seem to keep array info in my head for very long without forgetting it.

Just change his _ArrayToString($FileList) To _ArrayToString($FileList, "|", 1) to get rid of that number.

Another Method is

$cData = ""
For $i = 1 To Ubound($FileList)-1
 $cData &= "|" & $fileList[$i]
Next
GUICtrlSetData($MyControl, $cData)
;;Or GUICtrlSetData($MyControl, $cData, $FileList[1])

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Thanks GEOSoft! That does it perfectly.

Just change his _ArrayToString($FileList) To _ArrayToString($FileList, "|", 1) to get rid of that number.

Another Method is

$cData = ""
For $i = 1 To Ubound($FileList)-1
 $cData &= "|" & $fileList[$i]
Next
GUICtrlSetData($MyControl, $cData)
;;Or GUICtrlSetData($MyControl, $cData, $FileList[1])

Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0