Jump to content

Listview with a Checkbox and array help


KeeWay
 Share

Recommended Posts

hello, i have been using autoit for a while for basic scripting and now a task has come across my desk and i have never dealt with arrays or the gui interface that much.

I have a few problems and would greatly appreciate any help in solving my lack of programming skills :) .

the way the program is supposed to work is it will monitor a directory for files that will be populated all day long. the user will select one or many files then hit the print button, this will then move the files into a specified directory.

the problems i am currently having and have not been able to figure out is:

1. an automatic and manual refresh procedure to refresh the window.

2. a way to determine the actual files names once the checkbox has been marked to move them to the folder determined by the button press. (currently it only displays a number).

3. if multiple files are checked move them to a folder, which i believe is an array but i am not sure how to handle this.

here is my current code i have come up with so far.

thanks in advance

james

CODE
#include <file.au3>

#include <GUIConstantsEx.au3>

#include <TreeViewConstants.au3>

#include <array.au3>

dim $FILE, $DIR

$DIR = "c:\loftware\inbound\"

$FILE = _FileListToArray($DIR,"*",1)

Main()

Func Main()

$GUI = GUICreate("Example",400,400)

$LISTVIEW = GuiCtrlCreateTreeView(5, 5, 390, 150, $TVS_CHECKBOXES)

For $INDEX = 1 To $FILE[0]

$POINT = StringInStr($FILE[$INDEX],".",0,-1)

If $POINT <> 0 Then

GUICtrlCreateTreeViewItem($FILE[$INDEX], $LISTVIEW)

;GUICtrlSetData(-1, $FILE[$INDEX])

EndIf

Next

$Read = GUICtrlCreateButton("Print", 10, 160, 50)

GUICtrlSetState(-1, $GUI_FOCUS)

GUISetState()

$msg = 0

$menu1 = GUICtrlCreateMenu("File")

$refresh = GUICtrlCreateMenuItem("Refresh", $menu1)

$separator1 = GUICtrlCreateMenuItem("", $menu1, 2) ; create a separator line

$exititem = GUICtrlCreateMenuItem("Exit", $menu1)

While $msg <> $GUI_EVENT_CLOSE

$msg = GUIGetMsg()

Select

Case $msg = $Read

$menutext = GUICtrlRead($menu1, 1) ; return the text of the menu item

If GUICtrlRead($LISTVIEW) = "" Then

MsgBox(0, "No Selection", "Please Make A Selection") ; display the selected listbox entry

Else

MsgBox(0, "Selected listbox entry", GUICtrlRead($LISTVIEW)) ; display the selected listbox entry

; this is where the program will move the selected files to the specified folder for printing.

EndIf

Case $msg = $exititem

ExitLoop

EndSelect

WEnd

EndFunc

Link to comment
Share on other sites

You might want to use ListBox with multiple line selection enabled and then upon button event or so process the list items to see if an item is selected and move it to the special folder, for each listbox item you can attach item info (maybe string of path...).

Can't give you exact example because I'm not a machine, read the help file :)

Edited by Authenticity
Link to comment
Share on other sites

I use this code to generate the files list:

; Shows the filenames of all FILES in the current directory.
    $search = FileFindFirstFile($server_path & $project & "\RAW\*.*")
 
; Check IF the search was successful
    IF $search = -1 THEN
        MsgBox(0, "Error", "SERVER UNREACHABLE.")
        EXIT
    EndIf
 
    WHILE 1
        $file = FileFindNextFile($search)
        IF @ERROR THEN ExitLoop
        GUICtrlCreateListViewItem($file, $listview)
    WEND
 
; CLOSE the search handle
    FileClose($search)

Hope this help much..

forgot to include the COPY function where it copy the list that has been checked.

Func _Copy()
    LOCAL $item_count = _GUICtrlListView_GetItemCount($listview)
    LOCAL $is_checked, $items_checked, $file_array[1], $dest
    FOR $i = 0 TO $item_count - 1
        $is_checked = _GUICtrlListView_GetItemChecked($listview, $i)
        IF NOT @ERROR THEN
            $items_checked += $is_checked
            IF ($is_checked) THEN
                IF ($items_checked = 1) THEN
                    _ArrayInsert($file_array, 0, _GUICtrlListView_GetItemTextString($listview, $i))
                    _ArrayDelete($file_array, 1)
                ELSE
                    _ArrayAdd($file_array, _GUICtrlListView_GetItemTextString($listview, $i))
                EndIf
            EndIf
        EndIf
    NEXT
;_ArrayDisplay($file_array, "Files Selected")
    
    IF ($items_checked <> 0) THEN
        $dest = FileSelectFolder("Choose a folder.", "", 1)
        IF NOT @ERROR THEN
            FOR $i = 0 TO $items_checked - 1
                SplashTextOn("", @LF & "Copying..." & @LF & $file_array[$i], 300, 70, -1, -1, 1, "Arial", 10, 800)
                FileCopy($server_path & $project & "\RAW\" & $file_array[$i], $dest, 1)
            NEXT
            SplashOff()
        EndIf
    ELSE
        MsgBox(0, "", "No Items Selected")
    EndIf
    EXIT
EndFunc ;;==>_Copy
Edited by nfaustin
[font="Palatino Linotype"][size="2"]*** The information contained in this post should be considered and certified WORKS ON MY MACHINE ***[/size][/font][font="Palatino Linotype"][size="2"] [/size][/font]
Link to comment
Share on other sites

nfaustin, thanks i appreciate you going out of your way to try and help me...

I looked at and tried your code but i could not figure out on the main gui screen the capability of adding of checkboxes using the ListView options. the only way i could get the checkboxes in place in the window is via the TreeView but i see that probably the _Copy function will not work using the TreeView.

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...