Jump to content

What is the proper method to use _GUICtrlListView_DeleteItem :(


Digisoul
 Share

Recommended Posts

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

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

Link to comment
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()
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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

Link to comment
Share on other sites

  • 3 months later...

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...