foamRoller Posted March 8, 2010 Posted March 8, 2010 I've made a listview that displays file paths | date last modded, and a progress bar that shows how up to date my list is (which works). I also have a refresh button that should empty the listview and then repopulate it with entries. Except it keeps the old entries. Seems like a common issue but I couldn't find anything on the forums or help files on it (started autoit about 2 weeks ago). I also have an extra column called "11" that I didn't intend on adding, but persists... below is the code, it won't run for you unless you add some variables including an array of files. I'm pretty sure the problem lies in my use of _GUICtrlListView_DeleteAllItems and _GuiCtrlListView_AddItem. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GuiStatusBar.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <TabConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <GuiTab.au3> Opt("GUIOnEventMode", 1) Global $mainGUI = GUICreate("tst", 700, 364, 234, 170) GUISetIcon("D:\005.ico") Global $options = GUICtrlCreateTab(8, -1, 684, 343) GUICtrlSetResizing($options, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) Global $dates = GUICtrlCreateTabItem("dates") Global $refresh = GUICtrlCreateButton("check refresh dates", 32, 39, 147, 30, $WS_GROUP) GUICtrlSetFont($refresh, 8, 400, 0, "Arial") GUICtrlSetOnEvent($refresh, "refreshClick") Global $ref_progress = GUICtrlCreateProgress(202, 49, 192, 17) $reflist = GUICtrlCreateListView($dates, 32, 75, 550, 175) _GUICtrlListView_SetExtendedListViewStyle($reflist, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) _GUICtrlListView_InsertColumn($reflist, 0, "files", 250) _GUICtrlListView_InsertColumn($reflist, 1, "times", 300) GUISetState() While 1 Sleep(100) WEnd Func refreshClick() ;refresh file creation dates _GUICtrlListView_DeleteAllItems($reflist) $reflist_default = GUICtrlCreateListViewItem("today|" & $today, $reflist) Local $ref_hold, $ref_prog For $i = 0 To UBound($file_list) - 1 #cs here i grab the getfiletimes of the files in my list array _GUICtrlListView_AddItem($reflist, _LTRIM($file_list[$i], $root), $i) $ref_hold = convertTime(FileGetTime($file_list[$i])) _GUICtrlListView_AddSubItem($reflist, $i, $ref_hold, 1) If $ref_hold <> "N/A" Then $ref_prog = $ref_prog + 1 #ce EndIf Next GUICtrlSetData($ref_progress, $ref_prog / $num_files * 100) EndFunc ;==>refreshClick
Moderators Melba23 Posted March 8, 2010 Moderators Posted March 8, 2010 foamRoller,Welcome to the AutoIt forum. A good start - some code to work on and a clear question. I wish some other newcomers would do the same. However, next time could you please provide the missing elements - I do not mind debugging, but I am not very keen on writing code to make someone else's code actually work! Anyway, to the code:1. The extra column. You were creating the ListView thus:$reflist = GUICtrlCreateListView($dates, 32, 75, 550, 175)$dates is the TabItem you have just created, so you are setting the column header to the ControID of that TabItem. You then add 2 further column and so now have 3! Best to do what i have done - create the ListView with the header titles and then set the widths (note the use of the $LVSCW_AUTOSIZE_USEHEADER constant to autosize the final column.2. The items. If you create a ListView with the built-in GUICtrlCreateListView, then you must use the built_in GUICtrlCreateListViewItem to set the items. Mixing the built-in and UDF functions is often fatal - although as you can see from the point above, you can get away with it sometimes if you are not actually creating controls. 3. File Time. As I have no idea what your convertTime function does, I presume you are getting the correct results and do not need to add any parameters to the call as I have had to do.4. $reflist_default. I presume you know what this is supposed to do! All it does for me is add an extra line (once I added a valid variable). OK, the modified script:expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GuiStatusBar.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <TabConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <GuiTab.au3> #include <File.au3> Opt("GUIOnEventMode", 1) Global $mainGUI = GUICreate("test", 700, 364, 234, 170) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetIcon("D:\005.ico") Global $options = GUICtrlCreateTab(8, -1, 684, 343) GUICtrlSetResizing($options, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) Global $dates = GUICtrlCreateTabItem("dates") Global $refresh = GUICtrlCreateButton("check refresh dates", 32, 39, 147, 30) GUICtrlSetFont($refresh, 8, 400, 0, "Arial") GUICtrlSetOnEvent($refresh, "refreshClick") Global $ref_progress = GUICtrlCreateProgress(202, 49, 192, 17) $reflist = GUICtrlCreateListView("files|times", 32, 75, 550, 175) _GUICtrlListView_SetExtendedListViewStyle($reflist, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) _GUICtrlListView_SetColumnWidth($reflist, 0, 250) _GUICtrlListView_SetColumnWidth($reflist, 1, $LVSCW_AUTOSIZE_USEHEADER) GUISetState() While 1 Sleep(10) WEnd Func _Exit() Exit EndFunc Func refreshClick() ;refresh file creation dates _GUICtrlListView_DeleteAllItems($reflist) $reflist_default = GUICtrlCreateListViewItem("today|" & @MDAY, $reflist) Local $ref_hold, $ref_prog For $i = 1 To UBound($file_list) - 1 ; here i grab the getfiletimes of the files in my list array $ref_hold = FileGetTime($file_list[$i], 0, 1) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlCreateListViewItem($file_list[$i] & "|" & $ref_hold, $reflist) ; <<<<<<<<<<<<<<<<< Next ;GUICtrlSetData($ref_progress, $ref_prog / $num_files * 100) EndFunc ;==>refreshClickI have run it using _FileListToArray on the script folder to get an array of filenames and it works without problem for me.I hope it does for you too. Please ask if anything is unclear or not working as you wish. 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
foamRoller Posted March 8, 2010 Author Posted March 8, 2010 Thanks, your response helped me a lot - I removed that extra column, and $LVSCW_AUTOSIZE_USEHEADER is a neat trick. It also refreshes properly now, and I caught a few other bugs that I made. Point taken on the UDF function mixing, it was definitely the source of troubles. Here's a look at what I'm making in case it was unclear, next time I'll make sure the code is runnable.
Moderators Melba23 Posted March 8, 2010 Moderators Posted March 8, 2010 foamRoller, Glad I could help. 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
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