amphoric

Multi Select List Box - Read Selections

4 posts in this topic

#1 ·  Posted

I have created a simple GUI and would like to read out which selections I select from my multi selection list box, so I can eventually run a loop on the selected items.

My current code is below,,, I just cant get it to read out a single selection let alone multiple :(

Thanks in advance

 

 

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>

;Include and Install required files on run of compiled script
Local $bFileInstall = True ; Change to True and ammend the file paths accordingly.

; On 'run' this will install the files to C:\Packaging\ Packaging Upload v1.0
DirCreate ("C:\Pack\PackUpload v1.0\Required")
If $bFileInstall Then FileInstall( "H:\!! Applications\Pack Upload\Pack Upload v1.0\Folders.ini", "C:\Pack\Pack Upload v1.0\Required\Folders.ini", $FC_NOOVERWRITE)

;_Apps Local Directory
Global $_Apps = "C:\Pack\_Apps"
Global $aFileList, $PackageListItems, $sAvailableFolders

;Include The INI File
$sIniPath = "C:\Packaging\ Packaging Upload v1.0\Required\Folders.ini"

;Read the INI file section names
Local $aArray = IniReadSectionNames($sIniPath)
If @error Then Exit MsgBox(0, "Error", "returned @error = " & @error)
;Convert to a string for loading into combo
$sPackageTypes = ""
For $i = 1 To $aArray[0]
    $sPackageTypes &= "|" & $aArray[$i]
Next

PackageList()
GUI()
Func GUI()



#Region ### START GUI section ###
$Form1_1 = GUICreate("  - Package Upload", 436, 460, -1, -1)
GUISetIcon("C.ico", -1)
GUISetBkColor(0xFFFFFF)
$ProceedBtn = GUICtrlCreateButton("Proceed", 128, 392, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x008000)
$CancelBtn = GUICtrlCreateButton("Cancel", 240, 392, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$Logo = GUICtrlCreatePic(".jpg", 24, 8, 159, 33)
$PackageUploadLabel = GUICtrlCreateLabel("Package Upload", 224, 8, 187, 28, BitOR($SS_RIGHT,$SS_CENTERIMAGE))
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
$CreatedByLabel = GUICtrlCreateLabel("Created By  ITES", 16, 432, 405, 15, $SS_CENTER)
GUICtrlSetFont(-1, 7, 400, 0, "MS Sans Serif")
$VerLabel = GUICtrlCreateLabel("Ver. 1.0 ALPHA", 328, 40, 79, 17)
$Step1Label = GUICtrlCreateLabel("1. Select The Required Package(s) To Upload", 24, 80, 386, 20, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000080)
GUICtrlSetBkColor(-1, 0xE3E3E3)
$Graphic3 = GUICtrlCreateGraphic(16, 72, 404, 356, BitOR($GUI_SS_DEFAULT_GRAPHIC,$SS_SIMPLE))
GUICtrlSetColor(-1, 0xE3E3E3)
GUICtrlSetBkColor(-1, 0xE3E3E3)
Global $PackageList = GUICtrlCreateList("", 24, 104, 385, 100, BitOR($LBS_NOTIFY,$LBS_SORT,$WS_VSCROLL, $LBS_MULTIPLESEL, $LBS_EXTENDEDSEL))
GUICtrlSetData(-1, $PackageListItems)
$Step2Label = GUICtrlCreateLabel("2. Select The Required Upload Directory", 24, 216, 386, 20, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000080)
GUICtrlSetBkColor(-1, 0xE3E3E3)
$PackageTypeCombo = GUICtrlCreateCombo("", 24, 264, 185, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, $sPackageTypes)
$PackageTypeLabel = GUICtrlCreateLabel("Package Type:", 25, 242, 111, 17, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
GUICtrlSetBkColor(-1, 0xE3E3E3)
$PackageStateCombo = GUICtrlCreateCombo("", 224, 264, 185, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetState($PackageStateCombo, $GUI_DISABLE)
$PackageStateLabel = GUICtrlCreateLabel("Package State:", 225, 242, 111, 17, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
GUICtrlSetBkColor(-1, 0xE3E3E3)
$IfFileExistsLabel = GUICtrlCreateLabel("If the file exists would you like to:", 25, 298, 383, 17, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
GUICtrlSetBkColor(-1, 0xE3E3E3)
$Group1 = GUICtrlCreateGroup("", 24, 312, 385, 65)
$OverwriteRadio = GUICtrlCreateRadio("OverwriteRadio", 32, 324, 81, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xE3E3E3)
$SkipRadio = GUICtrlCreateRadio("SkipRadio", 32, 348, 49, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xE3E3E3)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label5 = GUICtrlCreateLabel("If Package Exists", 120, 323, 106, 20, $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xE3E3E3)
$Label6 = GUICtrlCreateLabel("If Package Exists", 85, 347, 106, 20, $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xE3E3E3)
GUISetState(@SW_SHOW)
#EndRegion ### END GUI section ###



While 1
    $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                ExitLoop

        Case $CancelBtn
            Exit

        Case $PackageTypeCombo
            ; Read the $PackageTypeCombo combo
            $SelectedType = GUICtrlRead($PackageTypeCombo)
            ;Read the avaliable folders in that section
            $AvailableFolders = IniReadSection($sIniPath, $SelectedType)
            ;If there are folders convert to string
            If IsArray($AvailableFolders) Then
                $sAvailableFolders = ""
                For $i = 1 To $AvailableFolders [0][0]
                    $sAvailableFolders &= "|" & $AvailableFolders[$i][0]
                Next
                GUICtrlSetData($PackageStateCombo, $sAvailableFolders)
                GUICtrlSetState($PackageStateCombo, $GUI_ENABLE)
            EndIf


            Case $ProceedBtn

                $sItem = GUICtrlRead(GUICtrlRead($PackageList))
  $sItem = StringTrimRight($sItem, 1) ; Will remove the pipe "|" from the end of the string
  MsgBox(0, "Selected Item", $sItem)


    EndSwitch
WEnd

EndFunc

Func PackageList()
    ; List all the folders in the _Apps directory using the default parameters.
    Local $aFileList = _FileListToArray($_Apps, "*")
        $sFileList = ""
        For $i = 1 To $aFileList [0]
            $sFileList &= "|" & $aFileList[$i]
        Next
        $PackageListItems = $sFileList
    If @error = 1 Then
        MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.")
        Exit
    EndIf
    If @error = 4 Then
        MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
        Exit
    EndIf


EndFunc

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

amphoric,

As you have a multiple selection ListBox, you need to use the UDF functions _GUICtrlListBox_GetSelItems/GetSelItemsText to get all the selections into an array. GUICrlRead will only return the last selected item - and why are you using it twice when trying to read the ListBox at the moment? You only need to do that with ListViews, which are very different beasts.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

That's perfect! Thanks so much for your help Melba23!!!

Another quick question if I may? How would I now loop through and run an action for each of the selected Listbox items?

Cheers

Share this post


Link to post
Share on other sites

#4 ·  Posted

amphoric,

Use a For...Next loop to run through the items in the returned array, what else?

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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