Jump to content

_FilelistToArray


 Share

Recommended Posts

Have read the Help section, but still questioning..

_FilelistToArray
 
If I use _FileListToArray to show a list of files (for example - CMy FilesMy Stuff),
should I then be able to use _GUICtrlListView_AddArray to display the results in a ListView?
 
For instance: (just including the script in question)
 
$List4 = GUICtrlCreateListview("", 192, 72, 470, 260) ;create the ListView etc. to get the control displayed etc
 
$aFileList = _FileListToArray("CMy Files|My Stuff" , "*") ;to get all the files in this directory
_GUICtrlListView_AddArray($List4,$aFileList )  ;get results into ListView
 
Should that add the whole array to the ListView?  Or is a For/Next routine still needed, although it would seem to defeat the purpose of the previous command.
 
I know I can get it done with a For/Next routine and using GUICtrlCreateListViewItem, but was just looking for any alternative as well.
When I use _FileListToArray, I can get and display an array, so it appears to work there, but if I go further and add the script
_GUICtrlListView_AddArray, it does not add the results to the ListView. 
 
Thanks
Hobbyist
Link to comment
Share on other sites

  • Moderators

Hobbyist,

_GUICtrlListView_AddArray requires a 2D array while _FilelistToArray returns a 1D array - hence your problem. I would stick with a loop if I were you. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

You can modify the functions (ctrl+j, while cursor is inside the function name)...you can make a local copy, like this, for 1 or 2d arrays:

#include <File.au3>
#include <GuiListView.au3>
lOCAL $ARRAY = _FileListToArray(@DesktopDir)
_ArrayDelete($ARRAY,0)

; Create GUI
GUICreate("ListView Add Array", 400, 300)
$hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
_GUICtrlListView_AddColumn($hListView, "Items", 100)
GUISetState()

; Add columns
_GUICtrlListView_AddArray_($hListView,$ARRAY)
Func _GUICtrlListView_AddArray_($hWnd, ByRef $aItems)
    If $Debug_LV Then __UDF_ValidateClassName($hWnd, $__LISTVIEWCONSTANT_ClassName)

    Local $fUnicode = _GUICtrlListView_GetUnicodeFormat($hWnd)

    Local $tItem = DllStructCreate($tagLVITEM)
    Local $tBuffer
    If $fUnicode Then
        $tBuffer = DllStructCreate("wchar Text[4096]")
    Else
        $tBuffer = DllStructCreate("char Text[4096]")
    EndIf
    DllStructSetData($tItem, "Mask", $LVIF_TEXT)
    DllStructSetData($tItem, "Text", DllStructGetPtr($tBuffer))
    DllStructSetData($tItem, "TextMax", 4096)
    Local $iLastItem = _GUICtrlListView_GetItemCount($hWnd)
    _GUICtrlListView_BeginUpdate($hWnd)
    If IsHWnd($hWnd) Then
        If _WinAPI_InProcess($hWnd, $_lv_ghLastWnd) Then
            For $iI = 0 To UBound($aItems) - 1
                DllStructSetData($tItem, "Item", $iI)
                DllStructSetData($tItem, "SubItem", 0)
                If UBound($aItems,0) = 1 Then
                    DllStructSetData($tBuffer, "Text", $aItems[$iI])
                Else
                    DllStructSetData($tBuffer, "Text", $aItems[$iI][0])
                EndIf
                _SendMessage($hWnd, $LVM_INSERTITEMW, 0, $tItem, 0, "wparam", "struct*")
                For $iJ = 1 To UBound($aItems, 2) - 1
                    DllStructSetData($tItem, "SubItem", $iJ)
                    DllStructSetData($tBuffer, "Text", $aItems[$iI][$iJ])
                    _SendMessage($hWnd, $LVM_SETITEMW, 0, $tItem, 0, "wparam", "struct*")
                Next
            Next
        Else
            Local $iBuffer = DllStructGetSize($tBuffer)
            Local $iItem = DllStructGetSize($tItem)
            Local $tMemMap
            Local $pMemory = _MemInit($hWnd, $iItem + $iBuffer, $tMemMap)
            Local $pText = $pMemory + $iItem
            DllStructSetData($tItem, "Text", $pText)
            For $iI = 0 To UBound($aItems) - 1
                DllStructSetData($tItem, "Item", $iI + $iLastItem)
                DllStructSetData($tItem, "SubItem", 0)
                If UBound($aItems,0) = 1 Then
                    DllStructSetData($tBuffer, "Text", $aItems[$iI])
                Else
                    DllStructSetData($tBuffer, "Text", $aItems[$iI][0])
                EndIf
                _MemWrite($tMemMap, $tItem, $pMemory, $iItem)
                _MemWrite($tMemMap, $tBuffer, $pText, $iBuffer)
                If $fUnicode Then
                    _SendMessage($hWnd, $LVM_INSERTITEMW, 0, $pMemory, 0, "wparam", "ptr")
                Else
                    _SendMessage($hWnd, $LVM_INSERTITEMA, 0, $pMemory, 0, "wparam", "ptr")
                EndIf
                For $iJ = 1 To UBound($aItems, 2) - 1
                    DllStructSetData($tItem, "SubItem", $iJ)
                    DllStructSetData($tBuffer, "Text", $aItems[$iI][$iJ])
                    _MemWrite($tMemMap, $tItem, $pMemory, $iItem)
                    _MemWrite($tMemMap, $tBuffer, $pText, $iBuffer)
                    If $fUnicode Then
                        _SendMessage($hWnd, $LVM_SETITEMW, 0, $pMemory, 0, "wparam", "ptr")
                    Else
                        _SendMessage($hWnd, $LVM_SETITEMA, 0, $pMemory, 0, "wparam", "ptr")
                    EndIf
                Next
            Next
            _MemFree($tMemMap)
        EndIf
    Else
        Local $pItem = DllStructGetPtr($tItem)
        For $iI = 0 To UBound($aItems) - 1
            DllStructSetData($tItem, "Item", $iI + $iLastItem)
            DllStructSetData($tItem, "SubItem", 0)
            If UBound($aItems,0) = 1 Then
                DllStructSetData($tBuffer, "Text", $aItems[$iI])
            Else
                DllStructSetData($tBuffer, "Text", $aItems[$iI][0])
            EndIf
            If $fUnicode Then
                GUICtrlSendMsg($hWnd, $LVM_INSERTITEMW, 0, $pItem)
            Else
                GUICtrlSendMsg($hWnd, $LVM_INSERTITEMA, 0, $pItem)
            EndIf
            For $iJ = 1 To UBound($aItems, 2) - 1
                DllStructSetData($tItem, "SubItem", $iJ)
                DllStructSetData($tBuffer, "Text", $aItems[$iI][$iJ])
                If $fUnicode Then
                    GUICtrlSendMsg($hWnd, $LVM_SETITEMW, 0, $pItem)
                Else
                    GUICtrlSendMsg($hWnd, $LVM_SETITEMA, 0, $pItem)
                EndIf
            Next
        Next
    EndIf
    _GUICtrlListView_EndUpdate($hWnd)
EndFunc   ;==>_GUICtrlListView_AddArray
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

  • Moderators

jdelaney,

Thanks for posting that. I will look into modifying the function over the weekend. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Not that it breaks anything, but the second loop might as well be in their respective else statments :).

Kind of defeats the purpose of a list anyways...probably should just use a listbox.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
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...