Champak Posted November 24, 2011 Posted November 24, 2011 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
Moderators Melba23 Posted November 24, 2011 Moderators Posted November 24, 2011 Champak, It is always a good idea to post some working code rather than relying on the reader to fill in the missing lines. 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: #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? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Champak Posted November 24, 2011 Author Posted November 24, 2011 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. expandcollapse popup#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
Moderators Melba23 Posted November 24, 2011 Moderators Posted November 24, 2011 Champak,Sorry for the delay in replying - dinner called! 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. So if you fill the ListView like this:GUICtrlCreateListViewItem($DirList[$I], $GUI_List)you should find that the items are deleted without problem. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Champak Posted November 24, 2011 Author Posted November 24, 2011 Great that did it, but now the folder wont delete. I'll look into that later, I got to go and do the family thing now. Thanks.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now