YawStar Posted August 21, 2018 Posted August 21, 2018 (edited) expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> Global $Form1, $ListView1, $btn_RemoveAll, $btn_RemoveAllFinished, $LVGroup_Unfinished, $LVGroup_Finished #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Remove Finished Items", 615, 389, -1, -1) $ListView1 = GUICtrlCreateListView("Name|Status", 8, 8, 594, 318) _GUICtrlListView_SetColumnWidth($ListView1, 0, 285) _GUICtrlListView_SetColumnWidth($ListView1, 1, 300) _GUICtrlListView_EnableGroupView($ListView1, True) $LVGroup_Finished = _GUICtrlListView_InsertGroup($ListView1, -1, 1, "Finished", 0) $LVGroup_Unfinished = _GUICtrlListView_InsertGroup($ListView1, -1, 2, "Unfinished", 0) $btn_RemoveAll = GUICtrlCreateButton("Remove All", 136, 344, 115, 33) $btn_RemoveAllFinished = GUICtrlCreateButton("Remove All Finished", 341, 342, 115, 33) GUISetState(@SW_SHOW) _Create_ListViewItems() #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btn_RemoveAll _RemoveAllItems() Case $btn_RemoveAllFinished _GUICtrlListView_DeleteAllItems($LVGroup_Finished) EndSwitch WEnd Func _RemoveAllItems() _GUICtrlListView_DeleteAllItems($ListView1) EndFunc ;==>_RemoveAllItems Func _Create_ListViewItems() For $i = 1 To 20 If $i < 8 Then $iIndex = _GUICtrlListView_AddItem($ListView1, "Test Item-" & $i) _GUICtrlListView_AddSubItem($ListView1, $iIndex, "Finished", 1) _GUICtrlListView_SetItemGroupID($ListView1, $iIndex, 1) Else $iIndex = _GUICtrlListView_AddItem($ListView1, "Test Item-" & $i) _GUICtrlListView_AddSubItem($ListView1, $iIndex, "Unfinished", 1) _GUICtrlListView_SetItemGroupID($ListView1, $iIndex, 2) EndIf Next EndFunc ;==>_Create_ListViewItems Hi, I am the beginner of autoit script. Is there possible to delete all items from specific ListView group. Here is my example script. Thank. Remove_Finished_Items.au3 Edited August 21, 2018 by YawStar
Moderators Melba23 Posted August 21, 2018 Moderators Posted August 21, 2018 (edited) YawStar, Here is my attempt: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> Global $Form1, $ListView1, $btn_RemoveAll, $btn_RemoveAllFinished ; Create group IDs Enum $LVGroup_Finished = 1, $LVGroup_Unfinished $Form1 = GUICreate("Remove Finished Items", 615, 389, -1, -1) $ListView1 = GUICtrlCreateListView("Name|Status", 8, 8, 594, 318) _GUICtrlListView_SetColumnWidth($ListView1, 0, 285) _GUICtrlListView_SetColumnWidth($ListView1, 1, 300) _GUICtrlListView_EnableGroupView($ListView1, True) _GUICtrlListView_InsertGroup($ListView1, -1, $LVGroup_Finished, "Finished", 0) _GUICtrlListView_InsertGroup($ListView1, -1, $LVGroup_Unfinished, "Unfinished", 0) $btn_RemoveAll = GUICtrlCreateButton("Remove All", 136, 344, 115, 33) $btn_RemoveAllFinished = GUICtrlCreateButton("Remove All Finished", 341, 342, 115, 33) GUISetState(@SW_SHOW) _Create_ListViewItems() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btn_RemoveAll _RemoveAllItems() Case $btn_RemoveAllFinished _RemoveGroupItems($ListView1, $LVGroup_Finished) EndSwitch WEnd Func _RemoveAllItems() _GUICtrlListView_DeleteAllItems($ListView1) EndFunc ;==>_RemoveAllItems Func _RemoveGroupItems($hWnd, $iGroup) ; Based i=on single remove item code ; Determine ListView type Local $vCID = 0 If IsHWnd($hWnd) Then ; Check if the ListView has a ControlID $vCID = _WinAPI_GetDlgCtrlID($hWnd) Else $vCID = $hWnd ; Get ListView handle $hWnd = GUICtrlGetHandle($hWnd) EndIf ; Loop through Items For $iIndex = _GUICtrlListView_GetItemCount($hWnd) - 1 To 0 Step -1 ; Note reverse loop ; Check Item group If _GUICtrlListView_GetItemGroupID($hWnd, $iIndex) = $iGroup Then ; If native ListView - could be either type of item If $vCID < $_UDF_STARTID Then ; Try deleting as native item Local $iParam = _GUICtrlListView_GetItemParam($hWnd, $iIndex) ; Check if LV item If GUICtrlGetState($iParam) > 0 And GUICtrlGetHandle($iParam) = 0 Then GUICtrlDelete($iParam) EndIf EndIf ; Has to be UDF Listview and/or UDF item _SendMessage($hWnd, $LVM_DELETEITEM, $iIndex) EndIf Next EndFunc Func _Create_ListViewItems() For $i = 1 To 20 If $i < 8 Then $iIndex = _GUICtrlListView_AddItem($ListView1, "Test Item-" & $i) _GUICtrlListView_AddSubItem($ListView1, $iIndex, "Finished", 1) _GUICtrlListView_SetItemGroupID($ListView1, $iIndex, $LVGroup_Finished) Else $iIndex = _GUICtrlListView_AddItem($ListView1, "Test Item-" & $i) _GUICtrlListView_AddSubItem($ListView1, $iIndex, "Unfinished", 1) _GUICtrlListView_SetItemGroupID($ListView1, $iIndex, $LVGroup_Unfinished) EndIf Next EndFunc ;==>_Create_ListViewItems Please ask if you have any questions. M23 Edited August 21, 2018 by Melba23 Added comments YawStar and Zedna 2 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
YawStar Posted August 21, 2018 Author Posted August 21, 2018 Thank @Melba23 . You are amazing.Your script work for me. That is exactly what i find. Have a nice day.
Moderators Melba23 Posted August 21, 2018 Moderators Posted August 21, 2018 YawStar, Glad I could help - and I learnt some more about ListView groups into the bargain. M23 YawStar 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
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