Altor Posted November 8, 2016 Share Posted November 8, 2016 (edited) Hi all: I wish I could load GUICtrlSetData with a array for work with the GUICtrlCreateCombo control....and not use the tipical: GUICtrlSetData($idComboBox, "Item 2|Item 3", "Item 2") How could you do ...if it is possible Thank's to all Edited November 8, 2016 by Altor Link to comment Share on other sites More sharing options...
Tekk Posted November 8, 2016 Share Posted November 8, 2016 #include <ComboConstants.au3> ; Create a combobox control. Local $idComboBox = GUICtrlCreateCombo("", 10, 10, 185, 20) Local $aComboItems = ["Item 1", "Item 2", "Item 3"] ; Add array items to the combobox. For $i = 0 To UBound($aComboItems) -1 GUICtrlSendMsg($idComboBox, $CB_ADDSTRING, 0, $aComboItems[$i]) Next Local $iSelected = 0 ; Set default selection at index 0 GUICtrlSendMsg($idComboBox, $CB_SETCURSEL, $iSelected, 0) Link to comment Share on other sites More sharing options...
AutoBert Posted November 8, 2016 Share Posted November 8, 2016 The classic way with GuiCtrlSetData: expandcollapse popup#cs ----------------------------------------------------------------------------------------------------------- AutoIt Version: 3.3.6.1 Author: AutoBert: http://autoit.de/index.php?page=Thread&postID=164341#post164341 Skriptbeispiel für den Umgang mit INI-Files und ComboBox #ce ----------------------------------------------------------------------------------------------------------- #include <GUIConstantsEx.au3> #Include <GuiComboBox.au3> #include <StaticConstants.au3> Const $sElect = "bitte eine URL auswählen" Const $sAppIni=@AppDataDir&"\URLs.INI" Global $URL If Not FileExists($sAppIni) Then $sData = "AutoIt=http://autoit.de" & @LF $sData &= "Buch=http://autoit.de/index.php?page=Thread&postID=92818#post92818" & @LF $sData &= "richtig Posten=http://autoit.de/index.php?page=Thread&threadID=4424" & @LF $sData &= "Tutorial=http://wiki.autoit.de/wiki/index.php/Tutorial" & @LF $sData &= "Skriptfehler finden=http://autoit.de/index.php?page=Thread&threadID=13785" & @LF $sData &= "Hilfe=http://translation.autoit.de/autoitinfo/hilfedateien/AutoIt-Hilfe-Deutsch-3.3.6.1-Stand-09_05_10.zip" & @LF $sData &= "MiniUrl-Manger=http://autoit.de/index.php?page=Thread&postID=164341#post164341" & @LF IniWriteSection($sAppIni, "URLs", $sData) EndIf $hGui = GUICreate("MiniUrl-Manager", 300, 90, 302, 218) $idcboProg = GUICtrlCreateCombo("", 8, 8, 200, 25) $idbtnAdd = GUICtrlCreateButton("&Hinzufügen", 213, 8,80) $idbtnDel = GUICtrlCreateButton("&Löschen", 213, 35,80) $idlblURL = GUICtrlCreateLabel("", 8, 70, 290,25) $idbtnOpen = GUICtrlCreateButton("&Öffnen", 8, 35,200) GUICtrlSetState($idbtnOpen, $GUI_DISABLE) GUICtrlCreateGraphic(0,65,300,2,$SS_ETCHEDHORZ ) read_INI() GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idbtnAdd $write1 = InputBox("URL", "Bitte eine gültige URL eingeben") If $write1 <> "" Then $write2 = InputBox("URL verwalten unter", "Bitte Kurzbegriff eingeben") If $write2 <> "" Then IniWrite($sAppIni, "URLs", $write2, $write1) GUICtrlSetData($idcboProg, $write2, $write2) EndIf show_Selection() Case $idbtnDel $sDel = GUICtrlRead($idcboProg) IniDelete($sAppIni, "URLs", $sDel) GUICtrlSetData($idcboProg,"") read_INI() Case $idcboProg show_Selection() Case $idbtnOpen ShellExecute($URL) ;ConsoleWrite($URL & @CRLF) EndSwitch WEnd Func read_INI() $list1 = IniReadSection($sAppIni, "URLs") ConsoleWrite($list1 & @CRLF) if IsArray($list1) Then For $i = 1 To $list1[0][0] GUICtrlSetData($idcboProg, $list1[$i][0]) Next EndIf _GUICtrlComboBox_InsertString ($idcboProg,$sElect,0) _GUICtrlComboBox_SetCurSel($idcboProg,0) EndFunc ;==>read_INI Func show_Selection() If GUICtrlRead($idcboProg) = $sElect Then GUICtrlSetState($idbtnOpen, $GUI_DISABLE) GUICtrlSetData($idlblURL, "") Else GUICtrlSetState($idbtnOpen, $GUI_ENABLE) $Prog = GUICtrlRead($idcboProg) ConsoleWrite("ausgewählt: " & $Prog & @CRLF) $URL = IniRead($sAppIni, "URLs", $Prog, "") GUICtrlSetData($idlblURL, $URL) EndIf EndFunc ;==>show_Selection and the ini-file: [URLs] AutoIt General Help and Support=https://www.autoitscript.com/forum/forum/2-autoit-general-help-and-support/ AutoIt GUI Help and Support=https://www.autoitscript.com/forum/forum/10-autoit-gui-help-and-support/ https://www.autoitscript.com/forum/forum/14-autoitx-help-and-support/ AutoItX Help and Support=http://autoit.de/index.php?page=Thread&postID=92818#post92818 this is done in the func read_INI: Func read_INI() $list1 = IniReadSection($sAppIni, "URLs") ConsoleWrite($list1 & @CRLF) if IsArray($list1) Then For $i = 1 To $list1[0][0] GUICtrlSetData($idcboProg, $list1[$i][0]) Next EndIf _GUICtrlComboBox_InsertString ($idcboProg,$sElect,0) _GUICtrlComboBox_SetCurSel($idcboProg,0) EndFunc ;==>read_INI Link to comment Share on other sites More sharing options...
kylomas Posted November 8, 2016 Share Posted November 8, 2016 Altor, The simple way... #include <GUIConstantsEx.au3> #include <Array.au3> #include <GuiComboBox.au3> Local $Clients = ['Bobby', 'Joe', 'Susan', 'Alex', 'Yoda'] ;Create simple GUI $Form1 = GUICreate("Example", 150, 200) $List_Clients = GUICtrlCreateCombo("", 10, 10, 130, 200) GUICtrlSetData($List_Clients, _ArrayToString($Clients)) _GUICtrlComboBox_SetCurSel($List_Clients, 3) ; <<<----- set startup selection to 4TH entry GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $gui_event_close Exit Case $List_Clients MsgBox(0, 'Client', GUICtrlRead($List_Clients)) EndSwitch WEnd kylomas NicoLag 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Altor Posted November 8, 2016 Author Share Posted November 8, 2016 Thanks to Tekk, AutoBert and kylomas for yours exemples, with them I have been able to solve my doubts. It's a shame that the GUICtrlSetData can not directly load an array would make everything a little easier.... Thanks. 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