Renderer Posted October 25, 2020 Posted October 25, 2020 Hi Guys, I have little problem i got stuck with. In the script bellow in the TreeView are listed the Files and Folders of the "Scriptdir". When a Folder/Item from the Treeview is selected, the content of it is listed in the ListView. The problem is when I select a new Item/ Foder in the Treeview the old items from the previous Treeview selection remain in the Listview. How can I fix this problem, so that when I select a new Item in the Treeview the old Items from the Listview are Removed? Thanks in advance expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiToolbar.au3> #include <ListViewConstants.au3> #include <ToolbarConstants.au3> #include <TreeViewConstants.au3> #include <WindowsConstants.au3> #include <array.au3> #include <file.au3> #include <GuiTreeView.au3> #include <misc.au3> #include <GuiListView.au3> global $title global $tv_Style = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES) Func FileGetType($file) if StringInStr($file, ".") Then return StringSplit($file, ".", 1)[2] elseif not StringInStr($file, ".", 1) Then return "folder" EndIf EndFunc Func ListFiles_ToTreeView($hTreeView,$sSourceFolder, $hItem) Local $sFile, $newChild ; Force a trailing \ If StringRight($sSourceFolder, 1) <> "\" Then $sSourceFolder &= "\" ; Start the search Local $hSearch = FileFindFirstFile($sSourceFolder & "*.*") ; If no files found then return If $hSearch = -1 Then Return ; This is where we break the recursive loop <<<<<<<<<<<<<<<<<<<<<<<<<< ; Now run through the contents of the folder While 1 ; Get next match $sFile = FileFindNextFile($hSearch) ; If no more files then close search handle and return If @error Then ExitLoop ; This is where we break the recursive loop <<<<<<<<<<<<<<<<<<<<<<<<<< ; Check if a folder If @extended Then ; If so then call the function recursively $newChild = _GUICtrlTreeView_AddChild($hTreeView, $hItem, $sFile) ListFiles_ToTreeView($hTreeView, $sSourceFolder & $sFile, $newChild) Else ; If a file than write path and name _GUICtrlTreeView_AddChild($hTreeView, $hItem, $sFile) EndIf WEnd ; Close search handle FileClose($hSearch) return $newChild EndFunc ;==>ListFiles_ToTreeView Func _GUICtrlListView_CreateArray($hListView, $sDelimeter = '|') Local $iColumnCount = _GUICtrlListView_GetColumnCount($hListView), $iDim = 0, $iItemCount = _GUICtrlListView_GetItemCount($hListView) If $iColumnCount < 3 Then $iDim = 3 - $iColumnCount EndIf If $sDelimeter = Default Then $sDelimeter = '|' EndIf Local $aColumns = 0, $aReturn[$iItemCount + 1][$iColumnCount + $iDim] = [[$iItemCount, $iColumnCount, '']] For $i = 0 To $iColumnCount - 1 $aColumns = _GUICtrlListView_GetColumn($hListView, $i) $aReturn[0][2] &= $aColumns[5] & $sDelimeter Next $aReturn[0][2] = StringTrimRight($aReturn[0][2], StringLen($sDelimeter)) For $i = 0 To $iItemCount - 1 For $j = 0 To $iColumnCount - 1 $aReturn[$i + 1][$j] = _GUICtrlListView_GetItemText($hListView, $i, $j) Next Next Return SetError(Number($aReturn[0][0] = 0), 0, $aReturn) EndFunc ;==>_GUICtrlListView_CreateArray (guinness) Func _ArraysAreDuplicate($array1, $array2) local $output[0] for $i = 0 to UBound($array1) -1 if $array1[$i] = $array2[$i] Then _ArrayAdd($output, True) Else _ArrayAdd($output, False) EndIf Next if _ArraySearch($output, False) > -1 Then return False elseif _ArraySearch($output, False) = -1 Then Return True EndIf EndFunc if $cmdline[0] Then $title = $cmdline[1] Else $title = @ScriptDir EndIf global $drives_list = DriveGetDrive("ALL") _ArrayDelete($drives_list, 0) $hWin = GUICreate($title, 802, 551, 254, 46, BitOR($ws_sizebox, $ws_minimizebox, $ws_maximizebox)) $ToolBar1 = _GUICtrlToolbar_Create($hWin, BitOR($TBSTYLE_TOOLTIPS,$TBSTYLE_WRAPABLE,$TBSTYLE_ALTDRAG,$TBSTYLE_FLAT,$WS_GROUP,$WS_VISIBLE,$WS_CHILD,$WS_CLIPSIBLINGS)) $TreeView = GUICtrlCreateTreeView(0, 32, 305, 513, BitOR($GUI_SS_DEFAULT_TREEVIEW,$TVS_FULLROWSELECT,$TVS_NOSCROLL,$TVS_NONEVENHEIGHT,$WS_HSCROLL,$WS_VSCROLL,$WS_BORDER,$WS_CLIPSIBLINGS), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE)) $ListView = GUICtrlCreateListView("File | Date Of Creation | Type | Size | Link | ", 304, 32, 498, 490 ,BitOR($LVS_EDITLABELS,$WS_HSCROLL,$WS_VSCROLL)) GUISetState(@SW_SHOW) for $i = 0 to UBound($drives_list) -1 _GUICtrlTreeView_BeginUpdate($TreeView) local $file = ListFiles_ToTreeView($TreeView, $title , 0) _GUICtrlTreeView_EndUpdate($TreeView) Next global $list_folder global $current_view[0] global $trash[0] While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch local $current_selection = _GUICtrlTreeView_GetSelection($TreeView) local $selection_text = _GUICtrlTreeView_GetText($TreeView,$current_selection) if $current_selection > 0 Then local $select_folder_array = _FileListToArray(_GUICtrlTreeView_GetText($treeview, $current_selection)) for $i = 1 to UBound($select_folder_array) -1 if _ArraySearch($current_view, $select_folder_Array[$i]) = -1 Then if _ArraySearch($trash, $select_folder_array[$i]) = -1 Then _ArrayAdd($current_view, $select_folder_array[$i]) EndIf EndIf Next for $i = UBound($select_folder_array) -1 to 0 step -1 _ArrayDelete($select_folder_Array, $i) Next ; Refresh Folder Array EndIf for $i = UBound($current_view) -1 to 0 step -1 if _ArraySearch($current_view, $current_view[$i]) > -1 Then local $filename = $current_view[$i] local $link = $title & "\" & $selection_text & "\" & $filename local $date_array = FileGetTime($link, 1, 0) local $date_of_creation = $date_array[0] & "." & $date_array[1] & "." & $date_array[2] & "; " & $date_array[3] & ":" & $date_array[4] & ":" & $date_Array[5] local $file_type = FileGetType($link) local $file_size = FileGetSize($link) / 1024 if $file_size = 0 Then $file_size = "" EndIf if GUICtrlCreateListViewItem($filename & "|" & $date_of_creation & "|" & $file_type & "|" & $file_size & " KB" & "|" & $link, $ListView) Then _ArrayAdd($Trash, $current_view[$i]) EndIf if _ArraySearch($trash, $current_view[$i]) > -1 Then _ArrayDelete($current_view, $i) EndIf EndIf Next WEnd
GokAy Posted October 26, 2020 Posted October 26, 2020 (edited) Hey Renderer, Haven't used any ListViews yet. But, would this work for you? https://www.autoitscript.com/autoit3/docs/libfunctions/_GUICtrlListView_DeleteAllItems.htm Just call it right before adding new items. Edited October 26, 2020 by GokAy Wrong function corrected
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