Laura Posted February 23, 2013 Share Posted February 23, 2013 Hello, I'm using autoit for one week now. I'm new to programming, but i really enjoy playing around with it. Now, i'm trying to make a script that creates a listview from the data in a text file. The data in the listview should correspond to the data in the textfile, so if it gets updated, the listview should update aswell. When i run the script my listview items are properly created, but whenever i update the textfile, my array is getting updated, but my listview aint removing the old lines. _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hListView)) returns True _GUICtrlListView_GetItemCount($hListView) returns 0 But in fact nothing gets removed from my listview, and all the old items are displayed. Bug or just me being stupid? (Probably the last one ) What am i doing wrong? Any other approaches to this? While 1 $lines = _FileCountLines("\\Sharepc\Share\data.txt") If $lines <> $nrrows Then $csv = FileRead("\\Sharepc\Share\data.txt") $csv = StringStripWS($csv, 7) $rows = StringSplit($csv, @CRLF, 2) $nrrows = UBound($rows) Dim $entries[$nrrows + 1][5] For $i = 0 to $nrrows - 1 $temp = StringSplit($rows[$i], ";", 2) For $j = 0 to UBound($temp) - 1 $entries[$i][$j] = $temp[$j] Next Next ReDim $entries[$nrrows][4] _ArrayDisplay($entries) $deleteall = _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hListView)) ConsoleWrite($deleteall & @CRLF) $itemcount = _GUICtrlListView_GetItemCount($hListView) ConsoleWrite($itemcount & @CRLF) _GUICtrlListView_AddArray($hListView, $entries) EndIf WEnd Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 23, 2013 Moderators Share Posted February 23, 2013 (edited) Laura,There is a problem with the current _GUICtrlListView_DeleteAllItems function as explained in this thread. If you are creating your ListView with the native GUICtrlCreateListView function then that is probably why you cannot delete the items that you have inserted with the UDF _GUICtrlListView_AddArray function. The modified function I posted in that thread should be incorporated into the next release. Until then I suggest you either rewrite the script to use a UDF created ListView - or more easily - use that new function in your script. This example shows you how:expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <File.au3> $hGUI = GUICreate("Test", 500, 500) $cListView = GUICtrlCreateListView("", 10, 10, 404, 200) _GUICtrlListView_AddColumn($cListView, "Column 0", 100) _GUICtrlListView_AddColumn($cListView, "Column 1", 100) _GUICtrlListView_AddColumn($cListView, "Column 2", 100) _GUICtrlListView_AddColumn($cListView, "Column 3", 100) _Load_File("data.txt") $cButton = GUICtrlCreateButton("Reload", 10, 300, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton _Load_File("data.txt") EndSwitch WEnd Func _Load_File($sPath) ; Read the file into an array Local $aLines _FileReadToArray($sPath, $aLines) ; Create the array to hold the data - we now can size it correctly as the array holds the number of lines Local $aEntries[$aLines[0]][4] ; Loop through the lines For $i = 1 To $aLines[0] ; And split each one $aItems = StringSplit($aLines[$i], ";") ; Now loop through the separate items For $j = 1 To $aItems[0] ; And add them to the array to load into the ListView $aEntries[$i - 1][$j - 1] = $aItems[$j] Next Next ; Remove the curernt items using the new function _New_GUICtrlListView_DeleteAllItems($cListView) ; And load the new ones _GUICtrlListView_AddArray($cListView, $aEntries) EndFunc ;==>_Load_File Func _New_GUICtrlListView_DeleteAllItems($hWnd) If _GUICtrlListView_GetItemCount($hWnd) == 0 Then Return True If Not IsHWnd($hWnd) Then Local $ctrlID For $index = _GUICtrlListView_GetItemCount($hWnd) - 1 To 0 Step -1 $ctrlID = _GUICtrlListView_GetItemParam($hWnd, $index) If $ctrlID Then GUICtrlDelete($ctrlID) Next If _GUICtrlListView_GetItemCount($hWnd) = 0 Then Return True $hWnd = GUICtrlGetHandle($hWnd) EndIf Return _SendMessage($hWnd, $LVM_DELETEALLITEMS) <> 0 Return False EndFunc ;==>_New_GUICtrlListView_DeleteAllItemsI used the following file with 4 elements to each row - it seems to match your code: Item 00;Subitem 01;Subitem 02;Subitem 03 Item 10;Subitem 11;Subitem 12;Subitem 13 Item 20;Subitem 21;Subitem 22;Subitem 23 Item 30;Subitem 31;Subitem 32;Subitem 33 Item 40;Subitem 41;Subitem 42;Subitem 43If the data file is not in the correct format let me know and we can change the code to suit. All clear? M23Edit: Welcome to the AutoIt forum, by the way. Edited February 23, 2013 by Melba23 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 Link to comment Share on other sites More sharing options...
Laura Posted February 23, 2013 Author Share Posted February 23, 2013 Thank you! Works perfectly Really like your comments, I've learned a lot from them. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 23, 2013 Moderators Share Posted February 23, 2013 Laura, Seems like the old crystal ball still works! 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 Link to comment Share on other sites More sharing options...
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