Jump to content

GUIListView Delete Items from specific Group


YawStar
 Share

Recommended Posts

#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 by YawStar
Link to comment
Share on other sites

  • Moderators

YawStar,

Here is my attempt:

#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 by Melba23
Added comments

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

YawStar,

Glad I could help - and I learnt some more about ListView groups into the bargain.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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