Jump to content

Recommended Posts

Posted (edited)

Hope someone help me to get Total count of all checked listview items properly

her is my code :

 

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
        GUICreate("ListView Get/Set Item Checked State (v" & @AutoItVersion & ")", 400, 300)
        Local $idListview = GUICtrlCreateListView("", 2, 2, 394, 268)
        _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
        GUISetState(@SW_SHOW)

        ; Set ANSI format
;~     _GUICtrlListView_SetUnicodeFormat($idListview, False)

        ; Add columns
        _GUICtrlListView_AddColumn($idListview, "Column 0", 100)
        _GUICtrlListView_AddColumn($idListview, "Column 1", 100)
        _GUICtrlListView_AddColumn($idListview, "Column 2", 100)

        ; Add items
        _GUICtrlListView_AddItem($idListview, "Row 0: Col 0", 0)
        _GUICtrlListView_AddItem($idListview, "Row 1: Col 0", 1)
        _GUICtrlListView_AddItem($idListview, "Row 2: Col 0", 2)
        _GUICtrlListView_AddItem($idListview, "Row 3: Col 0", 3)
        _GUICtrlListView_AddItem($idListview, "Row 4: Col 0", 4)

        ; Check item 1
        _GUICtrlListView_SetItemChecked($idListview, 1)
        _GUICtrlListView_SetItemChecked($idListview, 2)
        _GUICtrlListView_SetItemChecked($idListview, 3)

        ;for $1x = _GUICtrlListView_GetItemCount($idListview) to 0 step -1

        $count = _GUICtrlListView_GetItemCount($idListview)
        For $1x = 0 To $count - 1
        $cSelectedItem2 = _GUICtrlListView_GetItemText($idListview, $1x, 0x0)
        If _GUICtrlListView_GetItemChecked ($idListview, $1x) = true then
            MsgBox(64+262144, "XXXXX", _GUICtrlListView_GetCheckedStates($idListview))
        EndIf
        Next

        ; Loop until the user exits.
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE
        GUIDelete()
EndFunc   ;==>Example

Func _GUICtrlListView_GetCheckedStates($hWnd) ; By guinness.
    Local $count = "", $aReturn = "", $bReturn = ""
    $count = _GUICtrlListView_GetItemCount($hWnd)
    For $i = 0 To $count - 1
        If _GUICtrlListView_GetItemChecked ($hWnd, $i) = true then
            $aReturn = $i & '|'
            $bReturn = StringTrimRight($aReturn, StringLen('|'))
        EndIf
    Next
    Return $bReturn
EndFunc   ;==>_GUICtrlListView_GetCheckedStates

Thanks in advance

Edited by Davidyese
  • Davidyese changed the title to Get Total Count of all Checked ListView Items properly
Posted (edited)
$count = _GUICtrlListView_GetCheckedStates($idListview)
;~  For $1x = 0 To $count - 1
;~      $cSelectedItem2 = _GUICtrlListView_GetItemText($idListview, $1x, 0x0)
;~      If _GUICtrlListView_GetItemChecked($idListview, $1x) = True Then
    MsgBox(64 + 262144, "XXXXX", "Checked count:" & $count)
;~      EndIf
;~  Next

Edit:
Get the MsgBox out of the for next loop.

it's not even necessary, everything is done in the function

Edited by ioa747

I know that I know nothing

Posted
8 minutes ago, ioa747 said:
$count = _GUICtrlListView_GetItemCount($idListview)
        For $1x = 0 To $count - 1
        $cSelectedItem2 = _GUICtrlListView_GetItemText($idListview, $1x, 0x0)
        If _GUICtrlListView_GetItemChecked ($idListview, $1x) = true then

        EndIf
        Next
        MsgBox(64+262144, "XXXXX", _GUICtrlListView_GetCheckedStates($idListview))

Edit:
Get the MsgBox out of the for next loop.

Excellent work

Thanks a lot my dear, it's working now

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...