Digisoul Posted September 16, 2009 Share Posted September 16, 2009 (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]=5now 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 September 16, 2009 by Digisoul 73 108 111 118 101 65 117 116 111 105 116 Link to comment Share on other sites More sharing options...
water Posted September 16, 2009 Share Posted September 16, 2009 (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 -1should do the trick. Edited September 16, 2009 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Digisoul Posted September 16, 2009 Author Share Posted September 16, 2009 (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 -1should do the trick. i already tried that trick Edited September 16, 2009 by Digisoul 73 108 111 118 101 65 117 116 111 105 116 Link to comment Share on other sites More sharing options...
water Posted September 16, 2009 Share Posted September 16, 2009 (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 September 16, 2009 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Digisoul Posted September 16, 2009 Author Share Posted September 16, 2009 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, 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. 73 108 111 118 101 65 117 116 111 105 116 Link to comment Share on other sites More sharing options...
Gui Posted January 14, 2010 Share Posted January 14, 2010 Try this : _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($List)) That will delete the selected. 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