Jump to content

Simple GUI with Listbox and some functions


Recommended Posts

Hello,

i tried to script a gui which shows me files of a previous chosen folder. I need a function to select all files in the list box. I also need a function to select just some files. At the moment this script isn´t working at all. I need some help to finish it.

Thanks!

Hacky

#include <GUIListBox.au3>

Dim $dateien[100]

#include <File.au3>

#include <Array.au3>

$ordner=FileSelectFolder("Choose folder", "")

$dateien=_FileListToArray ( $ordner ,"*",1)

Opt('MustDeclareVars', 1)

$Debug_LB = False

Local $hGUI, $sItems, $aItems, $hListBox

; Create GUI

$hGUI = GUICreate("Choose files for transfer", 400, 296)

$hListBox = GUICtrlCreateList("", 2, 2, 250, 296, BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL))

GUISetState()

; Add strings

_GUICtrlListBox_BeginUpdate ($hListBox)

For $i = 1 To 100

_GUICtrlListBox_AddString ($hListBox, $dateien[$i])

Next

_GUICtrlListBox_EndUpdate ($hListBox)

GUICtrlCreateButton("Select All Files", 200, 50)

GUICtrlCreateButton("Start Transfer", 200, 200)

; Loop until user exits

Do

until GUIGetMsg() = $GUI_EVENT_CLOSE

Link to post
Share on other sites

#include <GUIListBox.au3>
#include <File.au3>
#include <Array.au3>

Global $dateien[100]
$ordner=FileSelectFolder("Choose folder", "")
$dateien=_FileListToArray ( $ordner ,"*",1)
; Create GUI
$hGUI = GUICreate("Choose files for transfer", 400, 296)
$hListBox = GUICtrlCreateListView("", 2, 2, 250, 296, BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL))
GUISetState()
; Add strings
For $i = 1 To UBound($dateien)-1;here we make sure you don't exceed the array index of the file string variable using ubound, which is why it wasn't working
GUICtrlCreateListViewItem($dateien[$i], $hListBox)
Next
_GUICtrlListBox_EndUpdate ($hListBox)
GUICtrlCreateButton("Select All Files", 200, 50)
GUICtrlCreateButton("Start Transfer", 200, 200)
; Loop until user exits
Do
until GUIGetMsg() = $GUI_EVENT_CLOSE

Link to post
Share on other sites

#include <GUIListBox.au3>
#include <File.au3>
#include <Array.au3>

$ordner = FileSelectFolder("Choose folder", "")
$dateien = _FileListToArray($ordner, "*", 1)

; Create GUI
$hGUI = GUICreate("Choose files for transfer", 400, 296)
$hListBox = GUICtrlCreateList("", 2, 2, 250, 296, BitOr($GUI_SS_DEFAULT_LIST, $LBS_EXTENDEDSEL))
$btn_sel_all = GUICtrlCreateButton("Select All Files", 270, 50)
$btn_transfer = GUICtrlCreateButton("Start Transfer", 270, 200)
GUISetState()

; Add strings
_GUICtrlListBox_BeginUpdate($hListBox)
For $i = 1 To UBound($dateien) - 1
    _GUICtrlListBox_AddString($hListBox, $dateien[$i])
Next
_GUICtrlListBox_EndUpdate($hListBox)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $btn_sel_all
            _GUICtrlListBox_BeginUpdate($hListBox)
            GUICtrlSendMsg($hListBox, $LB_SETSEL, True, -1)
            _GUICtrlListBox_EndUpdate($hListBox)
        Case $msg = $btn_transfer
            $selected = ''
            For $i = 0 To _GUICtrlListBox_GetCount($hListBox) - 1
                If _GUICtrlListBox_GetSel($hListBox, $i) Then
                    $selected &= $i+1 & ': ' & _GUICtrlListBox_GetText($hListBox, $i) & @CRLF
                EndIf
            Next
            MsgBox(0, "Selected items", $selected)
    EndSelect
WEnd

Edited by Zedna
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...