Jump to content
Sign in to follow this  
luxactor

Need some help with ListView

Recommended Posts

luxactor

I've found some sample scripts here in forum and use them for my project, to list files/folders in a directory and show them in a dialog (later copy and burn them). Here my code:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GuiListView.au3>
#include <ListviewConstants.au3>
#Include <File.au3>
#Include <Array.au3>

Const $1GB = 1024 * 1024 * 1024
Const $1MB = 1024 * 1024
Const $1KB = 1024

$MAINGUI = GUICreate("Clips",482,302)
GUISetState()

$listview = GUICtrlCreateListView("#|Name|Größe|Erstellt am",5,40,470,200, -1, $LVS_EX_CHECKBOXES )
;~ _GUICtrlListView_SetColumnWidth($listview, 0, $LVSCW_AUTOSIZE_USEHEADER)
$button = GUICtrlCreateButton("Button",5,260,100,25)

$directory = "c:\Windows\"
$FileList=_FileListToArray($directory,'*.exe',  1) ; Only files
If @Error=1 Then
    MsgBox (0,"","keine dateien gefunden")
EndIf

For $n = 1 to UBound($FileList)-1
        $FileName = $FileList[$n]
        $FileSize = FileGetSize( $directory & "\" & $FileName)
        ;Dateigröße umrechnen
        Select
            Case $FileSize > $1GB
                $sApproximateSpace = $FileSize / $1GB
                $sComparison = "GB"
            Case $FileSize > $1MB And $FileSize < $1GB
                $sApproximateSpace = $FileSize / $1MB
                $sComparison = "MB"
            Case $FileSize >= "0"  And $FileSize < $1MB
                $sApproximateSpace = $FileSize / $1KB
                $sComparison = "KB"
            Case Else
        EndSelect
        If StringInStr($sApproximateSpace, ".") Then
            $sApproximateSpace = StringTrimRight($sApproximateSpace, StringLen($sApproximateSpace) - StringInStr($sApproximateSpace, ".") - 1)
        Else
        EndIf
        ;Dateiliste darstellen
        $FileTime =  FileGetTime($directory & "\" & $FileName, 1)
        $FileTimeDetail = $FileTime[2] & "/" & $FileTime[1] & "/" & $FileTime[0] & " " & $FileTime[3] & ":" & $FileTime[4] & ":" & $FileTime[5]
        $item = GUICtrlCreateListViewItem( "|" & $FileName & "|" & $sApproximateSpace & " " & $sComparison & "|" & $FileTimeDetail, $listview)
Next

While 1
    $m = GUIGetMsg()
    If $m = $GUI_EVENT_CLOSE Then Exit
    If $m = $button Then
        _Select()
    EndIf
WEnd

Func _Select()
    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
    If ($items_checked <> 0) Then
        If Not @ERROR Then
            FOR $i = 0 TO $items_checked - 1
                MsgBox(0, "", $file_array[$i])
            Next
            SplashOff()
        EndIf
    Else
        MsgBox(0, "", "blub")
    EndIf
    Sleep(10)
EndFunc

No my problem is, my Select() function and _GUICtrlListView_GetItemTextString inside it, shows me the whole text from the listview. For example: "|bfsvc.exe|69.5 KB|22/...", but I need only the filename. Can someone help plz? :)

Share this post


Link to post
Share on other sites
Melba23

luxactor,

In your Select() function, replace:

_GUICtrlListView_GetItemTextString($listview, $i)

with

_GUICtrlListView_GetItemText($listview, $i, 1)

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
luxactor

Thanks a lot, works perfectly! :)

Edited by luxactor

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
Sign in to follow this  

×