Sign in to follow this  
Followers 0
dazza

Catching Clicks in a ListView

3 posts in this topic

I'm being thick here. :P

I have a ListView called $scripts; it carries $LVS_EX_CHECKBOXES.

$scripts = GUICreateListView("SCRIPTS    | STATUS", 5, 5, 100, 100, -1, $LVS_EX_CHECKBOXES.)

I have used:

Opt("GUIOnEventMode", 1)

How do I:

1) When clicked in the listview, return the text e.g. script1

2) Loop through the listview, returning only those entries which have been ticked.

Thanks in advance.

Share this post


Link to post
Share on other sites



Hi,

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

Opt("GUIOnEventMode", 1)

$hGui = GUICreate('')
GUISetOnEvent($GUI_EVENT_CLOSE, "GuiEvent", $hGui)
$LV = GUICtrlCreateListView("SCRIPTS     | STATUS", 5, 5, 250, 200, -1, $LVS_EX_CHECKBOXES)
For $i = 1 To 10
    GUICtrlCreateListViewItem("Listview Item " & $i & "|OK" , $LV)
    GUICtrlSetOnEvent(-1, "GuiEvent")
Next
_GUICtrlListView_SetColumnWidth($LV, 0, $LVSCW_AUTOSIZE)
$Button = GUICtrlCreateButton("Get the Text of the checked Listview Items", 5, 210, 250, 20)
GUICtrlSetOnEvent(-1, "GuiEvent")
GUiSetState(@SW_SHOW, $hGui)

While 1
    Sleep(100)
WEnd

Func GuiEvent()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            Local $sTmp = ''
            For $i = 0 To _GUICtrlListView_GetItemCount($LV) -1
                If _GUICtrlListView_GetItemChecked($LV, $i) Then _
                    $sTmp &= "Listview Item CtrlID: " & _GUICtrlListView_GetItemParam($LV, $i) & @CRLF & _
                                "Listview Item Index: " & $i & @CRLF & _
                                "Listview Item Text: " & _GUICtrlListView_GetItemText($LV, $i) & @CRLF & @CRLF
            Next
            If $sTmp <> '' Then MsgBox(0, "CtrlID & Index & Text of Checked Listview Items:", $sTmp)
        Case Else
            For $i = 0 To _GUICtrlListView_GetItemCount($LV) -1
                If @GUI_CtrlId = _GUICtrlListView_GetItemParam($LV, $i) Then _
                    MsgBox(0, "CtrlID & Index & Text of Clicked Listview Item: ", _
                            "Listview Item CtrlID: " & _GUICtrlListView_GetItemParam($LV, $i) & @CRLF & _
                            "Listview Item Index: " & $i & @CRLF & _
                            "Listview Item Text: " & _GUICtrlListView_GetItemText($LV, $i), 2)
            Next            
    EndSwitch
EndFunc

You would be better off looking in the help file under User Defined Functions -> GuiListView Management.

You can find better example using GUIRegisterMsg()

Cheers

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Genius.

Many thanks

:P

Edited by dazza

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