gobsor Posted August 19, 2010 Share Posted August 19, 2010 Hey there! I'm using _GUICtrlListView_DeleteAllItems($hwnd) to clear the ListView in which I'm loading file information of the files contained by a folder that can be browsed. Somehow the MsgBox() only returns 'True' the first time I browse a folder. If I browse a second folder it says 'False', but I want to clear the ListView before information about files of a second folder are added to the ListView. expandcollapse popupFunc getInformation($path) MsgBox(0, "", _GUICtrlListView_DeleteAllItems($lview)) $ar = _FileListToArray($path, "*", 1) If @error == 4 Then MsgBox(0, "Error", "No Files found") Return ElseIf @error = 1 Then MsgBox(0, "Error", "Invalid path specified" Return EndIf For $i = 1 To $ar[0] Step 1 If($i < 10) Then _GUICtrlListView_AddItem($lview, "0"&$i) Else _GUICtrlListView_AddItem($lview, $i) EndIf _GUICtrlListView_AddSubItem($lview, $i-1, $ar[$i], 1) If(StringRight($ar[$i], 4) == ".mp3") Then _GUICtrlListView_AddSubItem($lview, $i-1, "MP3", 2) ElseIf((StringRight($ar[$i], 4) == ".jpg") Or (StringRight($ar[$i], 4) == ".jpeg")) Then _GUICtrlListView_AddSubItem($lview, $i-1, "JPG", 2) ElseIf(StringRight($ar[$i], 4) == ".png") Then _GUICtrlListView_AddSubItem($lview, $i-1, "PNG", 2) ElseIf(StringRight($ar[$i], 4) == ".gif") Then _GUICtrlListView_AddSubItem($lview, $i-1, "GIF", 2) ElseIf(StringRight($ar[$i], 4) == ".sfv") Then _GUICtrlListView_AddSubItem($lview, $i-1, "SFV", 2) ElseIf(StringRight($ar[$i], 4) == ".nfo") Then _GUICtrlListView_AddSubItem($lview, $i-1, "NFO", 2) ElseIf(StringRight($ar[$i], 4) == ".m3u") Then _GUICtrlListView_AddSubItem($lview, $i-1, "M3U", 2) Else _GUICtrlListView_AddSubItem($lview, $i-1, "OTHER", 2) EndIf $size = FileGetSize($path&"\"&$ar[$i]) If($size < 1024) Then _GUICtrlListView_AddSubItem($lview, $i-1, $size&" B", 3) ElseIf($size < 1048576) Then _GUICtrlListView_AddSubItem($lview, $i-1, Round($size/1024, 2)&" KB", 3) Else _GUICtrlListView_AddSubItem($lview, $i-1, Round($size/1048576, 2)&" MB", 3) EndIf Next EndFunc Any idea what I am doing wrong? greetings Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 19, 2010 Share Posted August 19, 2010 I don't think the problem is inside that function. It probably has more to do with when you called it. Post a short but complete script that uses that function and shows your symptoms. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
gobsor Posted August 22, 2010 Author Share Posted August 22, 2010 (edited) Allright, sorry for my late answer but I've been busy over the weekend. #include <GUIConstants.au3> #include <GuiListView.au3> GUICreate("", 400, 400) $hListView = GUICtrlCreateListView("Item|Subitem1|Subitem2|Subitem3|Subitem4", 5, 5, 390, 360) $hButton = GUICtrlCreateButton("DeleteAllItems()", 310, 367, 85, 30) GUISetState(@SW_SHOW) ; Row 1 _GUICtrlListView_AddItem($hListView, "01") _GUICtrlListView_AddSubItem($hListView, 0, "row 1 col 2", 1) _GUICtrlListView_AddSubItem($hListView, 0, "row 1 col 3", 2) _GUICtrlListView_AddSubItem($hListView, 0, "row 1 col 4", 3) _GUICtrlListView_AddSubItem($hListView, 0, "row 1 col 5", 4) ; Row 2 _GUICtrlListView_AddItem($hListView, "02") _GUICtrlListView_AddSubItem($hListView, 1, "row 2 col 2", 1) _GUICtrlListView_AddSubItem($hListView, 1, "row 2 col 3", 2) _GUICtrlListView_AddSubItem($hListView, 1, "row 2 col 4", 3) _GUICtrlListView_AddSubItem($hListView, 1, "row 2 col 5", 4) While 1 $msg = GUIGetMsg() If $msg == $GUI_EVENT_CLOSE Then ExitLoop If $msg == $hButton Then $return = _GUICtrlListView_DeleteAllItems($hListView) MsgBox(0, "Boolean", $return) EndIf WEnd When I press the button it tells me 'False' and nothing happens. Probably I'm using _GUICtrlListView_DeleteAllItems($hWnd) improperly? Greetings Edited August 22, 2010 by gobsor Link to comment Share on other sites More sharing options...
ReFran Posted August 22, 2010 Share Posted August 22, 2010 #include <GUIConstants.au3> #include <GuiListView.au3> GUICreate("", 400, 400) $hListView = GUICtrlCreateListView("Item|Subitem1|Subitem2|Subitem3|Subitem4", 5, 5, 390, 360) $hButton = GUICtrlCreateButton("DeleteAllItems()", 310, 367, 85, 30) GUISetState(@SW_SHOW) ; Row 1 _GUICtrlListView_AddItem($hListView, "01") _GUICtrlListView_AddSubItem($hListView, 0, "row 1 col 2", 1) _GUICtrlListView_AddSubItem($hListView, 0, "row 1 col 3", 2) _GUICtrlListView_AddSubItem($hListView, 0, "row 1 col 4", 3) _GUICtrlListView_AddSubItem($hListView, 0, "row 1 col 5", 4) ; Row 2 _GUICtrlListView_AddItem($hListView, "02") _GUICtrlListView_AddSubItem($hListView, 1, "row 2 col 2", 1) _GUICtrlListView_AddSubItem($hListView, 1, "row 2 col 3", 2) _GUICtrlListView_AddSubItem($hListView, 1, "row 2 col 4", 3) _GUICtrlListView_AddSubItem($hListView, 1, "row 2 col 5", 4) While 1 $msg = GUIGetMsg() If $msg == $GUI_EVENT_CLOSE Then ExitLoop If $msg == $hButton Then $return = _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hlistview)) MsgBox(0, "Boolean", $return) EndIf WEnd HTH, Reinhard Link to comment Share on other sites More sharing options...
gobsor Posted August 23, 2010 Author Share Posted August 23, 2010 Thanks a lot dude! Works just like a charm! I could have guessed it probably, but somehow I thought $hListView is the same that is returned by GUICtrlGetHandle($hWnd). kindly regards Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 23, 2010 Share Posted August 23, 2010 (edited) The native AutoIt GUI control functions are based on ControlID to make them easier to use. The control UDFs are almost entirely HWND handle based. Many of the help file examples are also sloppy with the difference between an integer ControlID and the actual HWND handles to things. Lately I've tried to make posted examples and demos more explicit by using, for example, $idLV for the ControlID and $hLV for the handle. So your control creation would have been: $idListView = GUICtrlCreateListView("Item|Subitem1|Subitem2|Subitem3|Subitem4", 5, 5, 390, 360) $hListView = GuiCtrlGetHandle($idListView) Making both the ID and handle available as required. Another problem is that using UDF functions like _GUICtrlListView_DeleteAllItems() on native AutoIt GUI controls sometimes produces unexpected/undesirable results. As a general rule, if you will be using UDF functions on a control then you should create it with the same UDF, i.e. with _GUICtrlListView_Create() vice GuiCtrlCreateListView(). Edited August 23, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
gobsor Posted August 24, 2010 Author Share Posted August 24, 2010 Allright, I will try to use the proper functions from now on. Sometimes I feel like an UDF is missing a certain function that is available on the native library, so I assume I can't avoid the mixing up of UDF and native functions all the time. Anyways, thanks for your explanation, might even show why I failed on certain other issues before (which showed unexpected behaviours (at least to me ). Regards 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