Jump to content

[Solved] How i can load a GUICtrlSetData with a array?


Altor
 Share

Recommended Posts

#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

The classic way with GuiCtrlSetData:

#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

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

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

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...