Sign in to follow this  
Followers 0
subfighter

How Can I Get What Checkboxes are Checked in GUICreateListView

5 posts in this topic

How Can I Get What Checkboxes are Checked in GUICreateListView? I am just using the example in the help file to create the LIST VIEW.

I got the CheckBoxes in the example below

What i need is when the BUTTON is clicked it would go through the LIST VIEW and tell me what ITEMS are Checked so i can run some commands on those Entries.

any help or examples.. i searched the forum but could not find anything exactly like this..

thanks

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>

;Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $listview, $button, $item1, $item2, $item3, $input1, $msg
    
    GUICreate("listview items", 300, 200, -1, -1, -1, $WS_EX_ACCEPTFILES)

    $listview = GUICtrlCreateListView("col1        |col2       |col3 ", 10, 10, 200, 150, -1, $LVS_EX_CHECKBOXES)
    $button = GUICtrlCreateButton("Get What Names Are Checked?", 75, 170, 170, 20)
    $item1 = GUICtrlCreateListViewItem("item1|col22|col23", $listview)
    $item2 = GUICtrlCreateListViewItem("item2|col12|col13", $listview)
    $item3 = GUICtrlCreateListViewItem("item3|c3332|col33", $listview)
    $item4 = GUICtrlCreateListViewItem("item4|44444|col33", $listview)
    $item5 = GUICtrlCreateListViewItem("item5|5555|col33", $listview)
    GUISetState()

    Do
        $msg = GUIGetMsg()
        
        Select
            Case $msg = $button
                MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)), 2)
            Case $msg = $listview
                MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2)
        EndSelect
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Like this...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
;#include <ListviewConstants.au3>
#include <GuiListView.au3>

Dim $item[6]

GUICreate("listview items", 300, 200, -1, -1, -1, $WS_EX_ACCEPTFILES)

$listview = GUICtrlCreateListView("col1        |col2       |col3 ", 10, 10, 200, 150, -1, $LVS_EX_CHECKBOXES)
$button = GUICtrlCreateButton("Get What Names Are Checked?", 75, 170, 170, 20)
$item[1] = GUICtrlCreateListViewItem("item1|col22|col23", $listview)
$item[2] = GUICtrlCreateListViewItem("item2|col12|col13", $listview)
$item[3] = GUICtrlCreateListViewItem("item3|c3332|col33", $listview)
$item[4] = GUICtrlCreateListViewItem("item4|44444|col33", $listview)
$item[5] = GUICtrlCreateListViewItem("item5|5555|col33", $listview)
GUISetState()

Do
 $msg = GUIGetMsg()

 Select
  Case $msg = $button
   For $x = 1 To 5
    If _GUICtrlListView_GetItemChecked($listview, $x - 1) Then
     MsgBox(0, "listview item", _GUICtrlListView_GetItemTextString($listview, $x - 1) & "    " & @CRLF & "Line Checked = " & $x, 2)
    EndIf
   Next
  Case $msg = $listview
   MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2)
 EndSelect
Until $msg = $GUI_EVENT_CLOSE

8)

Edited by Valuater
1 person likes this

NEWHeader1.png

Share this post


Link to post
Share on other sites

Like this...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
;#include <ListviewConstants.au3>
#include <GuiListView.au3>

Dim $item[6]

GUICreate("listview items", 300, 200, -1, -1, -1, $WS_EX_ACCEPTFILES)

$listview = GUICtrlCreateListView("col1        |col2       |col3 ", 10, 10, 200, 150, -1, $LVS_EX_CHECKBOXES)
$button = GUICtrlCreateButton("Get What Names Are Checked?", 75, 170, 170, 20)
$item[1] = GUICtrlCreateListViewItem("item1|col22|col23", $listview)
$item[2] = GUICtrlCreateListViewItem("item2|col12|col13", $listview)
$item[3] = GUICtrlCreateListViewItem("item3|c3332|col33", $listview)
$item[4] = GUICtrlCreateListViewItem("item4|44444|col33", $listview)
$item[5] = GUICtrlCreateListViewItem("item5|5555|col33", $listview)
GUISetState()

Do
 $msg = GUIGetMsg()

 Select
  Case $msg = $button
   For $x = 1 To 5
    If _GUICtrlListView_GetItemChecked($listview, $x - 1) Then
     MsgBox(0, "listview item", _GUICtrlListView_GetItemTextString($listview, $x - 1) & "    " & @CRLF & "Line Checked = " & $x, 2)
    EndIf
   Next
  Case $msg = $listview
   MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2)
 EndSelect
Until $msg = $GUI_EVENT_CLOSE

8)

thanks .. i was looking through help and missed... thanks again..

Share this post


Link to post
Share on other sites

thanks .. i was looking through help and missed... thanks again..

Actually, its not that easy to find... it took me a while too! for both of them in a loop

But, always try there first ( like you did )

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Without a GuiListView.au3 UDF:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>

Dim $item[6] = [5]

GUICreate("listview items", 300, 200, -1, -1, -1, $WS_EX_ACCEPTFILES)

$listview = GUICtrlCreateListView("col1        |col2       |col3 ", 10, 10, 200, 150, -1, $LVS_EX_CHECKBOXES)
$button = GUICtrlCreateButton("Get What Names Are Checked?", 75, 170, 170, 20)
$item[1] = GUICtrlCreateListViewItem("item1|col22|col23", $listview)
$item[2] = GUICtrlCreateListViewItem("item2|col12|col13", $listview)
$item[3] = GUICtrlCreateListViewItem("item3|c3332|col33", $listview)
$item[4] = GUICtrlCreateListViewItem("item4|44444|col33", $listview)
$item[5] = GUICtrlCreateListViewItem("item5|5555|col33", $listview)
GUISetState()

Do
    $msg = GUIGetMsg()
    Select
        Case $msg = $button
            For $i = 1 To $item[0]
                If BitAND(GUICtrlRead($item[$i], 1), $GUI_CHECKED) Then
                    MsgBox(0, "listview item", GUICtrlRead($item[$i]) & "    " & @CRLF & "Line Checked = " & $i, 2)
                EndIf
            Next
        Case $msg = $listview
            MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2)
    EndSelect
Until $msg = $GUI_EVENT_CLOSE

:mellow:

Share this post


Link to post
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
Sign in to follow this  
Followers 0