Sign in to follow this  
Followers 0
Nahuel

_GuiCtrllistview_DeleteAllItems not working when using imagelist.

11 posts in this topic

I want to delete all items of a list without having to destroy the image list, because the listview will be re-used.

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

Opt('MustDeclareVars', 1)

$Debug_LV = False; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

_Main()

Func _Main()
    Local $hImage, $hListView
    
    GUICreate("ListView Set Image List", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    GUISetState()

; Load images
    $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 16, 16))
    _GUICtrlListView_SetImageList($hListView, $hImage, 1)

; Add columns
    _GUICtrlListView_AddColumn($hListView, "Column 1", 100)
    _GUICtrlListView_AddColumn($hListView, "Column 2", 100)
    _GUICtrlListView_AddColumn($hListView, "Column 3", 100)

; Add items
    _GUICtrlListView_AddItem($hListView, "Item 1", 0)
    _GUICtrlListView_AddItem($hListView, "Item 2", 1)
    _GUICtrlListView_AddItem($hListView, "Item 3", 2)

; Get image list handle
    MsgBox(0,"","Now will try to delete all items!")
    if Not _GUICtrlListView_DeleteAllItems($hlistview) Then MsgBox(0,"","Didn't work :(")

; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc  ;==>_Main

Hope it's clear :)

Share this post


Link to post
Share on other sites



Use _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hListView))

:)


[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Use _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hListView))

:)

Yes, tried that. Works and it's incredibly faster, but the memory usage keeps growing. I read somewhere else that this is because that method doesn't delete the control id's.

Edited by Nahuel

Share this post


Link to post
Share on other sites

Yes, tried that. Works and it's incredibly faster, but the memory usage keeps growing. I read somewhere else that this is because that method doesn't delete the control id's.

try storing all of the control ids of the items in an array then use a for loop with _GUICtrlListView_DeleteItem($hWnd, $iIndex) to delete them all?

[size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N

Share this post


Link to post
Share on other sites

try storing all of the control ids of the items in an array then use a for loop with _GUICtrlListView_DeleteItem($hWnd, $iIndex) to delete them all?

That's pretty much what _GuiCtrlListView_DeleteAllItems does. And deleting the items one by one doesn't work either with the control ID's when using an imagelist.

Share this post


Link to post
Share on other sites

That's pretty much what _GuiCtrlListView_DeleteAllItems does. And deleting the items one by one doesn't work either with the control ID's when using an imagelist.

do what i said in combination with GUICtrlDelete ( controlID ) or try just using GUICtrlDelete ( controlID )

[size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N

Share this post


Link to post
Share on other sites

Thanks, but that doesn't work either.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Oh...

Are you tried with GUICtrlSetImage() to set images (and you will not need ImageList) ?

Little example :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $listview, $button, $item1, $item2, $item3, $input1, $msg
    
    GUICreate("listview items", 220, 250, -1, -1)

    $listview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150);,$LVS_SORTDESCENDING)
    $button = GUICtrlCreateButton("Value?", 75, 170, 70, 20)
    $item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview)
    $item2 = GUICtrlCreateListViewItem("item1|col12|col13", $listview)
    $input1 = GUICtrlCreateInput("", 20, 200, 150)
    GUISetState()
    GUICtrlSetData($item1, "ITEM1")
    GUICtrlSetData($item2, "||COL33")
    GUICtrlSetImage($item2, "shell32.dll", -5)
    GUICtrlDelete($item1)

    Do
    $msg = GUIGetMsg()
    Until $msg = $GUI_EVENT_CLOSE
EndFunc ;==>Example
Edited by n3nE

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Share this post


Link to post
Share on other sites

Being that the items were created using the UDFs you need to get the handle to the listview. Also might be a good idea to set the imagelist back to the old and destroy the new.

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

Opt('MustDeclareVars', 1)

$Debug_LV = False; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

_Main()

Func _Main()
    Local $hImage, $hListView, $hOld
    
    GUICreate("ListView Set Image List", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    GUISetState()

; Load images
    $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 16, 16))
    $hOld = _GUICtrlListView_SetImageList($hListView, $hImage, 1)

; Add columns
    _GUICtrlListView_AddColumn($hListView, "Column 1", 100)
    _GUICtrlListView_AddColumn($hListView, "Column 2", 100)
    _GUICtrlListView_AddColumn($hListView, "Column 3", 100)

; Add items
    _GUICtrlListView_AddItem($hListView, "Item 1", 0)
    _GUICtrlListView_AddItem($hListView, "Item 2", 1)
    _GUICtrlListView_AddItem($hListView, "Item 3", 2)

; Get image list handle
    MsgBox(0,"","Now will try to delete all items!")
    _GUICtrlListView_SetImageList($hListView, $hOld, 1)
    ConsoleWrite("Destroyed? " & _GUIImageList_Destroy($hImage) & @CRLF)
    if Not _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hlistview)) Then    MsgBox(0,"","Didn't work :(")

; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc  ;==>_Main

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Thank you :)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0