Jump to content

List item delete problem


Champak
 Share

Recommended Posts

Why am I unable to delete items from the list? The gui id works because I'm able to delete the directories with no problem. I keep getting a return of false. Is the checkbox preventing it from deleting, how do I get around it if that's the case?

$GUI_List = GUICtrlCreateListView("", 190, 2, 155, 240)
 _GUICtrlListView_SetExtendedListViewStyle($GUI_List, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
 



 For $I = 1 To _GUICtrlListView_GetItemCount($GUI_List)
  If _GUICtrlListView_GetItemChecked($GUI_List, $I) = True Then
   DirRemove($FileStorage & ":\" & _GUICtrlListView_GetItemText($GUI_List, $I))
   _GUICtrlListView_DeleteItem($GUI_List, $I)
  EndIf
 Next
Link to comment
Share on other sites

  • Moderators

Champak,

It is always a good idea to post some working code rather than relying on the reader to fill in the missing lines. :oops:

This code based on your snippets works fine for me. Note I reversed the order to delete from the bottom up - it is the only way to do it with arrays and is usually a good idea with lists too: :rip:

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

$hGUI = GUICreate("Test", 500, 500)

$GUI_List = GUICtrlCreateListView("                       ", 10, 10, 155, 240)
_GUICtrlListView_SetExtendedListViewStyle($GUI_List, $LVS_EX_CHECKBOXES)

For $i = 0 To 9
    GUICtrlCreateListViewItem("Item " & $i, $GUI_List)
Next

$hButton = GUICtrlCreateButton("Go", 10, 300, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            For $i = _GUICtrlListView_GetItemCount($GUI_List) To 1 Step -1 ; <<<<<<<<<<<< Reversed order
                If _GUICtrlListView_GetItemChecked($GUI_List, $i) = True Then
                    ;DirRemove($FileStorage & ":" & _GUICtrlListView_GetItemText($GUI_List, $i))
                    _GUICtrlListView_DeleteItem($GUI_List, $i)
                    Sleep(100)
                EndIf
            Next
    EndSwitch

WEnd

Does it work for you now? :D

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

Sorry, I thought it was something simple in the directly related code that I wasn't seeing or a known issue and didn't think to provide more code. Yeah, your version works, and others that I've done work, but it wont work as a function in my script. Here is the full version. Thanks.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=InfinitiM35XCreated.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Include <File.au3>
#Include <Array.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>

Opt("GUIOnEventMode", 1)
;#cs

Global $ASOURCE, $SetPath, $szDrive, $szDir, $szFName, $szExt, $SleepTime, $FileStorage, $PlaylistFolderPath

$REGLOCATION = "HKEY_CURRENT_USERSOFTWAREInfinitiM35X"
If RegRead($REGLOCATION, "Location") = "" Then
 RegWrite($REGLOCATION, "Location", "REG_SZ", "D")
EndIf
$FileStorage = RegRead($REGLOCATION, "Location")
If RegRead($REGLOCATION, "Sleep") = "" Then
 RegWrite($REGLOCATION, "Sleep", "REG_SZ", "10")
EndIf
$SleepTime = RegRead($REGLOCATION, "Sleep")

GUICreate("Infiniti M35X", 350, 300);, Default, Default, Default, $WS_EX_ACCEPTFILES)
 GUICtrlCreateLabel("Drive Letter:", 15, 19, 60, 15)
 $GUI_Location = GUICtrlCreateInput(RegRead($REGLOCATION, "Location"), 80, 17, 20, 20)
 GUICtrlCreateLabel("Sleep Time:", 15, 47, 60, 15)
 $GUI_Sleep = GUICtrlCreateInput(RegRead($REGLOCATION, "Sleep"), 80, 44, 30, 20)
 $GUI_Save = GUICtrlCreateButton("Save", 115, 15, 70, 50);, $BS_ICON)
 GUICtrlSetOnEvent($GUI_Save, "_Save")
 $GUI_FindPath = GUICtrlCreateButton("Playlist", 115, 80, 70, 50);, $BS_ICON)
 GUICtrlSetOnEvent($GUI_FindPath, "_FindFile")
; $GUI_Path = GUICtrlCreatePic("C:UsersNB7DesktopNoAlbumArt.gif", 15, 135, 170, 105)
 $GUI_Path = GUICtrlCreateLabel("X", 15, 135, 170, 105)
 GUICtrlSetFont($GUI_Path, 80, 900)
 GUICtrlSetStyle ( $GUI_Path, $SS_CENTER)
 GUICtrlSetState($GUI_Path, $GUI_DROPACCEPTED)
; GUISetOnEvent($GUI_EVENT_DROPPED, "_FindFile")
 GUICtrlSetBkColor($GUI_Path, 0x00ff00)
 $GUI_FilePath = GUICtrlCreateLabel("", 15, 250, 170, 40)
 GUICtrlSetFont($GUI_FilePath, 9.5, 500)
 GUICtrlSetBkColor($GUI_FilePath, 0xff0000)
 $GUI_List = GUICtrlCreateListView("", 190, 2, 155, 240)
 _GUICtrlListView_SetExtendedListViewStyle($GUI_List, $LVS_EX_CHECKBOXES)
 ;_GUICtrlListView_SetUnicodeFormat($GUI_List, False)
 $DirList = _FileListToArray("F:", "*", 2)
 If @error Then MsgBox(0,0,@error)
 _GUICtrlListView_AddColumn($GUI_List, "Playlist", 150)
 For $I = 1 To UBound($DirList) -1
  _GUICtrlListView_AddItem($GUI_List, $DirList[$I], 0)
 Next
 $GUI_Delete = GUICtrlCreateButton("Delete Playlist", 190, 250, 155, 40);, $BS_ICON)
 GUICtrlSetOnEvent($GUI_Delete, "_Delete")
 GUISetOnEvent($GUI_EVENT_CLOSE, '_onClose')
; GUIRegisterMsg(0x233, "On_WM_DROPFILES")
GUISetState()
While 1
 Sleep(100)
WEnd
#cs
Func _evDroppedFiles(ByRef $dFiles)
    local $x, $files;
    For $x = 0 To UBound($dFiles)-1
        $files &= $dFiles[$x] & @CRLF
    Next
    MsgBox(64, 'func1', StringTrimRight($files, 2));
 _Create($files)
EndFunc
Func On_WM_DROPFILES($hWnd, $Msg, $wParam, $lParam)
    Local $tDrop, $i, $aRet, $iCount;
    ;get file count
    $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "ptr", $wParam, "uint", -1, "ptr", 0, "uint", 0 )
    $iCount = $aRet[0]
    ;get file paths
    local $aDraggedFiles[$iCount];
    For $i = 0 To $iCount-1
        $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "ptr", $wParam, "uint", $i, "ptr", 0, "uint", 0)
        Local $tDrop = DllStructCreate("wchar[" & $aRet[0]+1 & "]")
        $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "ptr", $wParam, "uint", $i, "ptr", DllStructGetPtr($tDrop), "uint", $aRet[0]+1)
        $aDraggedFiles[$i] = DllStructGetData($tDrop, 1);
    Next
    ;finalize
    DllCall("shell32.dll", "int", "DragFinish", "ptr", $wParam)
    Return _evDroppedFiles($aDraggedFiles);
EndFunc
#ce
Func _onClose()
 Exit
EndFunc
Func _FindFile()
 $SetPath = RegRead($REGLOCATION, "Location")
 If $SetPath = "" Then
  MsgBox(0,"Destination Path Not Set", "Please set a destination path before proceeding.")
 Else
  $FindPath = FileOpenDialog("Playlist", "C:", "All (*.m3u)")
  If @error = 1 Then
   MsgBox(0,"Unknown File", "Unable to set file")
  Else
   _Create($FindPath)
  EndIf
 EndIf
EndFunc
Func _Delete()
 ;MsgBox(4160, "Deleted?", _GUICtrlListView_DeleteItem($GUI_List, 1))
 For $I = _GUICtrlListView_GetItemCount($GUI_List) To 1 Step -1
  If _GUICtrlListView_GetItemChecked($GUI_List, $I) = True Then
   DirRemove($FileStorage & ":" & _GUICtrlListView_GetItemText($GUI_List, $I))
   _GUICtrlListView_DeleteItem($GUI_List, $I)
  EndIf
 Next
EndFunc
Func _Create($Found)
 GUICtrlSetData($GUI_FilePath, "Counting files on CF")
 $DirSize = DirGetSize ($FileStorage & ":", 1)
 GUICtrlSetData($GUI_FilePath, "Track Count On CF: " & $DirSize[1])
 ;Read playlist to array
 _FileReadToArray($Found, $ASOURCE)
 If @error Then ConsoleWrite(@CR & @error & @CR)
 ;_ArrayDisplay($ASOURCE)
 _PathSplit($Found, $szDrive, $szDir, $szFName, $szExt)
 ;$PlaylistFolder = $szFName
 $PlaylistFolderPath = $FileStorage & ":" & $szFName
 $DirPlaylist = DirGetSize ($PlaylistFolderPath, 1)
 If @error = 1 Then
  $DirPlaylistCount = 0
  ;MsgBox(0,0,"Dir doesn't exist")
 Else
  $DirPlaylistCount = $DirPlaylist[1]
  ;MsgBox(0,0,"Dir does exist")
 EndIf

 $FileCount = $ASOURCE[0] + $DirSize[1] - $DirPlaylistCount
 If $FileCount > 512 Then
  $ExcededCount = $FileCount - 512
  MsgBox(17,"File Count", "You have exceeded the allowed track count by " & $ExcededCount & @CRLF & _
        "Delete files from the CF or current playlist.")
  Return
 EndIf

 For $I = $ASOURCE[0] To 0 Step -1
  ;Delete blank spaces in array
  If $ASOURCE[$I] = "" Then _ArrayDelete($ASOURCE, $I)
  ;Delete entries with "#EXTINFUTF8" which pops up with letters with the squiggly line above them and throws everything off
  If StringInStr($ASOURCE[$I], "#EXTINFUTF8") Then _ArrayDelete($ASOURCE, $I)
 Next
 ;Delete unneded elements in the beginning from array
 _ArrayDelete($ASOURCE, 0)
 _ArrayDelete($ASOURCE, 1)

 ;Delete #EXF entries in array
 For $I = UBound($ASOURCE) -2 To 0 Step -2
  _ArrayDelete($ASOURCE, $I)
 Next
 ;_ArrayDisplay($ASOURCE)
 ;Copy files and set modified date time stamp
 For $I = 0 To UBound($ASOURCE) - 1
  ;FileCopy($ASOURCE[$I], $PlaylistFolderPath & "")
  FileCopy($ASOURCE[$I], $PlaylistFolderPath & "", 8)
  $TestPath = _PathSplit($ASOURCE[$I], $szDrive, $szDir, $szFName, $szExt)
  GUICtrlSetData($GUI_FilePath, "  Progress: " & $I & " of " & UBound($ASOURCE) & @CRLF & "  " & $szFName); & $szExt)
  FileSetTime ( $PlaylistFolderPath & "" & $szFName & $szExt, "", 1 )
  Sleep($SleepTime)
 Next

 GUICtrlSetData($GUI_FilePath, "  Progress: " & $I & " of " & UBound($ASOURCE) & @CRLF & " Copy Complete")

 ;Strip path from playlist to compare against tracks in folder
 $var0 = $szDrive & $szDir
 $var1 = StringLen($var0)
 For $I = 0 To UBound($ASOURCE) - 1
  $new = StringTrimLeft($ASOURCE[$I], $var1)
  $ASOURCE[$I] = $new
 Next

 ;Read files in playlist folder and strip the path to compare against playlist
 $FolderArray = _FileListToArray($PlaylistFolderPath, "*.mp3", 1)
 $var1 = StringLen($PlaylistFolderPath)
 For $I = 0 To UBound($FolderArray) - 1
  StringTrimLeft($FolderArray[$I], $var1)
 Next
 _ArrayDelete($FolderArray, 0)

 ;Delete tracks no longer a part of the playlist from the folder
    For $J = 1 to UBound($FolderArray) -1
        If _ArraySearch ($ASOURCE, $FolderArray[$J]) = -1 Then
   FileDelete($PlaylistFolderPath & "" & $FolderArray[$J])
        EndIf
    Next
 GUICtrlSetData($GUI_FilePath, "  Progress: Process Complete")

EndFunc
Func _Save()
 If GUICtrlRead($GUI_Location, 1) <> "" Then
  RegWrite($REGLOCATION, "Location", "REG_SZ", GUICtrlRead($GUI_Location, 1))
 EndIf
 If GUICtrlRead($GUI_Sleep, 1) <> "" Then
  RegWrite($REGLOCATION, "Sleep", "REG_SZ", GUICtrlRead($GUI_Sleep, 1))
 EndIf
EndFunc
Link to comment
Share on other sites

  • Moderators

Champak,

Sorry for the delay in replying - dinner called! :rip:

Yuo are using the UDF function _GUICtrlListView_AddItem to add items to a ListView created with the built-in function GUICtrlCreateListView. Mixing UDF and native functions usually ends in tears - except in a few cases. ListViews are particularly sensitive in this regard - some of the UDF functions work very well with native ListViews; others do not. :oops:

So if you fill the ListView like this:

GUICtrlCreateListViewItem($DirList[$I], $GUI_List)

you should find that the items are deleted without problem. :D

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

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