Jump to content

_GUICtrlListView_InsertItem can't be deleted


CMJ
 Share

Recommended Posts

Can anyone help me here? I am using _GUICtrlListView_InsertItem to insert an item into my list but that item cannot be deleted later. GUICtrlCreateListViewItem does not seem to have this problem.

Here is a test script that shows this.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=Beta
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GuiConstantsEx.au3>
#include <GuiListView.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 $hListView

    GUICreate("ListView Insert Item", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    GUISetState()

    ; Insert columns
    _GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)

    GUICtrlCreateListViewItem("Item 1", $hListView)
    GUICtrlCreateListViewItem("Item 2", $hListView)
    GUICtrlCreateListViewItem("Item 3", $hListView)


    MsgBox(0,0,"Delete")
    Local $delete = _GUICtrlListView_DeleteAllItems($hListView)
    MsgBox(0,0,$delete)
    ; Add items
    _GUICtrlListView_InsertItem($hListView, "Item 1", 0)
    _GUICtrlListView_InsertItem($hListView, "Item 2", 1)
    _GUICtrlListView_InsertItem($hListView, "Item 3", 1)

    MsgBox(0,0,"Delete")

    $delete = _GUICtrlListView_DeleteAllItems($hListView)
    MsgBox(0,0,$delete)
    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

Thanks,

cj

Link to comment
Share on other sites

Don't mix standard controls with UDF-made controls!!

You can use

Local $delete = _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hListView))

to delete it, but you should use _GUICtrlListView_Create to create the listview.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

There seems to be a problem with deleting the last item of a listview. I'm sure it's a bug in the UDF but I haven't bothered looking for it. If that item is either moved up or another item created after it then the problem disappears.

Most of those GUI UDFs are screwed in one way or another.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

As funkey pointed out, the problem doesn't occur if you use a UDF created control with the UDF functions:

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>

Global $hGUI, $hListView, $delete

$hGUI = GUICreate("ListView Insert Item", 400, 300)
$hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 394, 268)
GUISetState()

; Insert columns
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)

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

; Prompt to delete
MsgBox(0, 0, "Delete")
$delete = _GUICtrlListView_DeleteAllItems($hListView)
MsgBox(0, 0, $delete)

; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

;)

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

Delete all items isn't an issue. Deleting only the last item on the control is. And I've tried it with both types of controls.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Thanks everyone for the reply. I was only vaguely aware of the differences between a UDF and standard control. As I am new here I had assumed that anything that was in the release was "standard". Now I understand and this makes sense of some of the problems that I have run into as I am learning AutoIt.

I cannot make the change that PsaltyDS and funkey suggested though I can confirm that it does work. In my case I am also using GUICtrlSetResizing which also seems to be incompatible with _GUICtrlListView_Create.

I did find a solution though. This works:

GUICtrlSendMsg($hListView, $LVM_DELETEALLITEMS, 0, 0)

See it in use here:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=Beta
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GuiConstantsEx.au3>
#include <GuiListView.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 $hListView

    GUICreate("ListView Insert Item", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    GUISetState()

    ; Insert columns
    _GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)

    GUICtrlCreateListViewItem("Item 1", $hListView)
    GUICtrlCreateListViewItem("Item 2", $hListView)
    GUICtrlCreateListViewItem("Item 3", $hListView)


    MsgBox(0,0,"Delete")
    Local $delete = _GUICtrlListView_DeleteAllItems($hListView)
    MsgBox(0,0,$delete)
    ; Add items
    _GUICtrlListView_InsertItem($hListView, "Item 1", 0)
    _GUICtrlListView_InsertItem($hListView, "Item 2", 1)
    _GUICtrlListView_InsertItem($hListView, "Item 3", 1)
    GUICtrlCreateListViewItem("Item 5", $hListView)

    MsgBox(0,0,"Delete")

    $delete = GUICtrlSendMsg($hListView, $LVM_DELETEALLITEMS, 0, 0)
    MsgBox(0,0,$delete)
    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

Thanks again for the help.

cj

Link to comment
Share on other sites

Following GEOsoft's suggestion that it may be a bug in the UDF I took a look at the _GUICtrlListView_DeleteAllItems function in the GUIListView.au3 Include. It seems to use another UDF - the SendMessage.au3 include - instead of sending the message directly to the control.

_SendMessage($hWnd, $LVM_DELETEALLITEMS)

instead of

GUICtrlSendMsg($hWnd, $LVM_DELETEALLITEMS, 0, 0)

Just swaping it out does not seem to fix it. So someone with more experience with AutoIt will have to troubleshoot this further, but maybe this is a point in the right direction.

cj

Edited by CMJ
Link to comment
Share on other sites

  • 10 months later...

Hi,

I just came across the same problem. Glad I found this topic.

Personally, I find it not to be such a bad idea to mix these functions, because some of them actually work well together.

For instance, it's much easier to deal with the internal ListView when you have Tab items (in this case, AutoIt automatically shows/hides the control when you switch between Tab items).

AutoIt's internal functions deal with ControlIDs, whereas with UDFs it has to deal with handles that can be recognized by the Windows API.

And this is at best an uneducated guess, but it appears that some UDF functions check for a valid handle before trying to perform the operation; when not found they perform the GUICtrlGetHandle() function to get that handle.

In many cases you can make it work that way.

So it might not be considered an actual bug, but more of an inconsistency.

footswitch

Edited by footswitch
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...