Sign in to follow this  
Followers 0
Digisoul

What is the proper method to use _GUICtrlListView_DeleteItem :(

6 posts in this topic

#1 ·  Posted (edited)

Hello there,

I am trying to delete the selected items from the list, but its left some items.

for example i select 3 random indices from the ListView and save them in array $sel_index

$sel_index[0]=0
$sel_index[1]=2
$sel_index[2]=5

now its successfully delete the item at 0 index,but its failed for all other indices, because the item index 2 become 1 and item index 5 become 4.

here is my code for deleting items

_GUICtrlListView_BeginUpdate($Lhwnd)
For $d = 0 to UBound($sel_index)-1
    $res = _GUICtrlListView_DeleteItem($Lhwnd,$sel_index[$d])
    ConsoleWrite("-"&@TAB&"Selected Index :"&$sel_index[$d]&" Result:"&$res&@CRLF)
Next
_GUICtrlListView_EndUpdate($Lhwnd)

Please tell me how can i handle this problem.

Thanks in advance for your help.

Edited by Digisoul

73 108 111 118 101 65 117 116 111 105 116

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If the item indexes are in ascending order in your array then simply change the direction of walking through the array. If they are in random order then first sort the array.

For $d = UBound($sel_index)-1 to 0 step -1
should do the trick. Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

If the item indexes are in ascending order in your array then simply change the direction of walking through the array.

its depend on user, how can i menage this ?

first sort the array.

Not work at all

For $d = UBound($sel_index)-1 to 0 step -1
should do the trick.

i already tried that trick :D Edited by Digisoul

73 108 111 118 101 65 117 116 111 105 116

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

When you start deleting the ListView from the highest to the lowest index it works fine. See this example:

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

Global $GUI
Global $sel_index[3] = [2,5,7]

$GUI = GUICreate("(UDF Created) ListView Create", 400, 300)
$hListView = _GUICtrlListView_Create($GUI, "", 2, 2, 394, 268)
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_AddItem($hListView, "Item 0")
_GUICtrlListView_AddItem($hListView, "Item 1")
_GUICtrlListView_AddItem($hListView, "Item 2")
_GUICtrlListView_AddItem($hListView, "Item 3")
_GUICtrlListView_AddItem($hListView, "Item 4")
_GUICtrlListView_AddItem($hListView, "Item 5")
_GUICtrlListView_AddItem($hListView, "Item 6")
_GUICtrlListView_AddItem($hListView, "Item 7")
_GUICtrlListView_AddItem($hListView, "Item 8")
_GUICtrlListView_AddItem($hListView, "Item 9")
_GUICtrlListView_AddItem($hListView, "Item 10")
_GUICtrlListView_AddItem($hListView, "Item 11")
_GUICtrlListView_AddItem($hListView, "Item 12")
GUISetState()
MsgBox(0,"","Deleting Item 2,5 and 7")

_GUICtrlListView_BeginUpdate($hListView)
For $d = UBound($sel_index)-1 To 0 Step -1
    $res = _GUICtrlListView_DeleteItem($hListView,$sel_index[$d])
    ConsoleWrite("-"&@TAB&"Selected Index :"&$sel_index[$d]&" Result:"&$res&@CRLF)
Next
_GUICtrlListView_EndUpdate($hListView)
GUISetState()
MsgBox(0,"","Deleted Item 2,5 and 7")
GUIDelete()
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

When you start deleting the ListView from the highest to the lowest index it works fine. See this example:

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

Global $GUI
Global $sel_index[3] = [2,5,7]

$GUI = GUICreate("(UDF Created) ListView Create", 400, 300)
$hListView = _GUICtrlListView_Create($GUI, "", 2, 2, 394, 268)
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_AddItem($hListView, "Item 0")
_GUICtrlListView_AddItem($hListView, "Item 1")
_GUICtrlListView_AddItem($hListView, "Item 2")
_GUICtrlListView_AddItem($hListView, "Item 3")
_GUICtrlListView_AddItem($hListView, "Item 4")
_GUICtrlListView_AddItem($hListView, "Item 5")
_GUICtrlListView_AddItem($hListView, "Item 6")
_GUICtrlListView_AddItem($hListView, "Item 7")
_GUICtrlListView_AddItem($hListView, "Item 8")
_GUICtrlListView_AddItem($hListView, "Item 9")
_GUICtrlListView_AddItem($hListView, "Item 10")
_GUICtrlListView_AddItem($hListView, "Item 11")
_GUICtrlListView_AddItem($hListView, "Item 12")
GUISetState()
MsgBox(0,"","Deleting Item 2,5 and 7")

_GUICtrlListView_BeginUpdate($hListView)
For $d = UBound($sel_index)-1 To 0 Step -1
    $res = _GUICtrlListView_DeleteItem($hListView,$sel_index[$d])
    ConsoleWrite("-"&@TAB&"Selected Index :"&$sel_index[$d]&" Result:"&$res&@CRLF)
Next
_GUICtrlListView_EndUpdate($hListView)
GUISetState()
MsgBox(0,"","Deleted Item 2,5 and 7")
GUIDelete()

Gr8 its working now, :D

I don't know why its not worked b4, might be coz of my any mistake.

anyways thank you very much for your kind help. :D


73 108 111 118 101 65 117 116 111 105 116

Share this post


Link to post
Share on other sites

Try this : _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($List))

That will delete the selected.

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