Davidyese Posted January 15 Posted January 15 (edited) Hope someone help me to get Total count of all checked listview items properly her is my code : expandcollapse popup#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 January 15 by Davidyese
Davidyese Posted January 15 Author Posted January 15 My code gives Checked items 3 items checked but repeated 3 times...!
ioa747 Posted January 15 Posted January 15 (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 January 15 by ioa747 Davidyese 1 I know that I know nothing
Davidyese Posted January 15 Author Posted January 15 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
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