Jump to content

Populate dropdown items with section names from .ini file


Cormin
 Share

Recommended Posts

I've never worked with an array or dropdown menu before and I can't seem to wrap it around my head this morning.  Maybe I just need more coffee but I'm trying to populate a GUI dropdown menu with section names of a .ini file.  Here is what I have for this part but I don't know where to go from here.  The msgbox thing was only testing it but I kinda got stuck here.

 

local $aSectionnames = IniReadSectionNames(@DesktopDir & "\Scripts\BatteryConfig.ini")

if Not @error Then
For $i = 1 to $aSectionnames[0]
    MsgBox($MB_SYSTEMMODAL, "Test", $aSectionnames[$i])
    Next
EndIf

 

Here is my very basic dropdown menu I want to populate

 

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 413, 213, 192, 124)
$Combo1 = GUICtrlCreateCombo("Combo1", 80, 24, 241, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Button1 = GUICtrlCreateButton("Button1", 152, 56, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

 

 

Thanks!

Link to comment
Share on other sites

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 413, 213, 192, 124)
$Combo1 = GUICtrlCreateCombo("", 80, 24, 241, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Button1 = GUICtrlCreateButton("Button1", 152, 56, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

; Get the sections of the ini file
Global $aSections = IniReadSectionNames(@DesktopDir & "\Scripts\BatteryConfig.ini")
; If the IniReadSectionNames succeeded, conver the array to a string with each item separated by a | (pipe) and set the default selected item to $aSections[1]
If (Not @Error) Then GUICtrlSetData($Combo1, _ArraytoString($aSections, "|", 1), $aSections[1])

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

You can use _ArrayToString to convert the array of sections to a string separated by a pipe (|) that you can use for GUICtrlSetData. I started the _ArrayToString at row 1 since the first element in the $aSections array is the # of sections (Useless information for a combobox).

Edited by InunoTaishou
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

×
×
  • Create New...