Jump to content

Determine whether ListViewItem OR was Checkbox clicked


Recommended Posts

Hi all,

do you know, how i can determine whether a whole ListViewItem was clicked or only the checkbox of a LVItem?

Because in any case the control ID of the correspondig LVItem is returned.

In case, i click a checkbox of an unselected LVItem, this LVItem won't be selected...

See example...

I could look through an array every time a LVItem/Checkbox is clicked, but isn't there a direct method?

Thanks for any help.

#include <GuiConstants.au3>
#include <GuiListView.au3>
Opt("GuiOnEventMode", 1)

$main = GUICreate("", 400, 200)
GUISetOnEvent($gui_event_close, "_quit")
GUISetFont(9, 400, 0, "Tahoma")

$list = GUICtrlCreateListView("|Col1|Col2", 20, 20, 360, 160, -1, $ws_ex_clientedge)
_GUICtrlListView_SetExtendedListViewStyle($list, BitOR($lvs_ex_checkboxes, $lvs_ex_fullrowselect))
_GUICtrlListView_SetColumnWidth($list, 0, 36)
_GUICtrlListView_SetColumnWidth($list, 1, 100)
_GUICtrlListView_SetColumnWidth($list, 2, 100)
    
For $i = 1 To 5
    GUICtrlCreateListViewItem("|Data" & $i & "|More" & $i, $list)
    GUICtrlSetOnEvent(-1, "_ItemAction")
Next

GUISetState()
While True
    Sleep(1000)
WEnd

Func _ItemAction()
    ;Item clicked or only its checkbox?
    ConsoleWrite("CtrlID: " & @GUI_CtrlId & @CRLF)
    
EndFunc

Func _quit()
    Exit
EndFunc
Link to comment
Share on other sites

Hmm, I'm not sure if there's a way of detecting if the actual Checkbox was clicked, but I guess you could determine if it was clicked by storing it's last state...

ie. If listviewitem is clicked then read and store the value in it, and next time determine if the new value of GuiCtrlRead($ListViewItem[x]) is not equal the last(stored) value, then you know if the checkbox was clicked or not...

Until someone provides a better solution... then I'm quite sure that's the only way to determine if the checkbox was clicked(unless you wanna go with some funky calculation where in your gui the user clicked... :))

Link to comment
Share on other sites

#include<ListViewConstants.au3>
#include<StructureConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
GUISetBkColor(0x00E0FFFF) ; will change background color

$listview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER), BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT));,$LVS_SORTDESCENDING)
$button = GUICtrlCreateButton("Value?", 75, 170, 70, 20)
$item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview)
$item2 = GUICtrlCreateListViewItem("item1|col12|col13", $listview)
$item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview)
$input1 = GUICtrlCreateInput("", 20, 200, 150)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)  ; to allow drag and dropping

GUIRegisterMsg($WM_NOTIFY, 'WM_Notify_Events')

GUICtrlSetData($item2, "ITEM1")
GUICtrlSetData($item3, "||COL33")
GUICtrlDelete($item1)

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

Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tagNMHDR, $event
    
    $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return
    $event = DllStructGetData($tagNMHDR, 3)
    Switch $event
        Case $NM_CLICK
            ConsoleWrite('!Click' & @CRLF)
        Case $NM_DBLCLK
            ConsoleWrite('!Double click' & @CRLF)
    EndSwitch
        
    $tagNMHDR = 0

    Return $GUI_RUNDEFMSG
EndFunc
I think this does what you want...

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

Der_Andi

Mayb this:

#include <GuiConstants.au3>
#include <GuiListView.au3>

$main = GUICreate("", 400, 200)
GUISetFont(9, 400, 0, "Tahoma")

$list = GUICtrlCreateListView("Col1|Col2", 20, 20, 360, 160, -1, $ws_ex_clientedge)
_GUICtrlListView_SetExtendedListViewStyle($list, BitOR($lvs_ex_checkboxes, $lvs_ex_fullrowselect))

_GUICtrlListView_SetColumnWidth($list, 0, 100)
_GUICtrlListView_SetColumnWidth($list, 1, 100)
_GUICtrlListView_SetColumnWidth($list, 2, 100)
    
For $i = 1 To 5
    _GUICtrlListView_AddItem($list, "Data")
    _GUICtrlListView_AddSubItem($list, $i -1, "More", 1)
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState()

Do
Until GUIGetMsg() = -3

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tNMHDR, $IdFrom, $iCode
    
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $IdFrom = DllStructGetData($tNMHDR, "IdFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    
    Switch $IdFrom
        Case $list
            Switch $iCode
                Case $NM_CLICK
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                    Local $iItem = DllStructGetData($tInfo, "Item")
                    
                    If $iItem <> -1 Then
                        Local $iX = DllStructGetData($tInfo, "ActionX")
                        If $iX < 21 Then
                            ConsoleWrite("Check" & @LF)
                        Else
                            ConsoleWrite("Click" & @LF)
                        EndIf
                    EndIf
                    
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc
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...