Jump to content

Double Click select item in Listviewitem


Recommended Posts

Hi all. I wanted to select item in listviewitem. what i have currently is to click item in listview then perform action when i click on selected item. What i wanted is to double click it instead of single click the item. i am using the $GUI_EVENT_PRIMARYDOWN to perform the action. Is there any way to double click the item then it will perform the desired function?

here is the sample code.

appreciate any suggestions and ideas. thanks.

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

Opt('MustDeclareVars', 1)
Dim $listview, $Btn_Get, $Btn_GetSelected, $Btn_Exit, $msg, $Status, $a_Item, $i, $input
GUICreate("ListView Get Item Text Array", 392, 322)

$listview = GUICtrlCreateListView("col1|col2|col3", 40, 30, 310, 149)
GUICtrlCreateListViewItem("line1|data1|more1", $listview)
GUICtrlCreateListViewItem("line2|data2|more2", $listview)
GUICtrlCreateListViewItem("line3|data3|more3", $listview)
GUICtrlCreateListViewItem("line4|data4|more4", $listview)
GUICtrlCreateListViewItem("line5|data5|more5", $listview)
$Btn_Exit = GUICtrlCreateButton("Exit", 300, 260, 70, 30)
$Status = GUICtrlCreateInput("", 50, 200, 40, 20)
$input = GUICtrlCreateInput("", 50, 230, 40, 20)

GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit
            ExitLoop
        Case $msg = $GUI_EVENT_PRIMARYDOWN
            $a_Item = _GUICtrlListView_GetItemTextArray($listview)
            If IsArray($a_Item) Then
                MsgBox(0, "", $a_Item)
                GUICtrlSetData($Status, "")
                GUICtrlSetData($Status, $a_Item[1])
                GUICtrlSetData($input, $a_Item[2])
            Else
                GUICtrlSetData($input, "")
            EndIf
    EndSelect
WEnd
Exit
Link to comment
Share on other sites

I use the following method:

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

Func WM_NOTIFY($hWnd, $MsgID, $wParam, $lParam)
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return 0
    $code = DllStructGetData($tagNMHDR, 3)
    If $wParam = $ListView And $code = -3 And _GUICtrlListView_GetSelectedCount($ListView) > 0 Then ;Put code here to deal with the double click
    Return $GUI_RUNDEFMSG
EndFunc
Edited by Marlo
Click here for the best AutoIt help possible.Currently Working on: Autoit RAT
Link to comment
Share on other sites

I use the following method:

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

Func WM_NOTIFY($hWnd, $MsgID, $wParam, $lParam)
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return 0
    $code = DllStructGetData($tagNMHDR, 3)
    If $wParam = $ListView And $code = -3 And _GUICtrlListView_GetSelectedCount($ListView) > 0 Then ;Put code here to deal with the double click
    Return $GUI_RUNDEFMSG
EndFunc
thanks Marlo. I'll try this.
Link to comment
Share on other sites

  • Moderators

JohnRichard,

I use a slightly different method. I set a flag when the double click is detected and then run code from within the While...WEnd loop. That way you return from the GUIRegisterMsg function ASAP - as recommended by the Help file: "the return to the system should be as fast as possible !!!".

So it looks something like this when put into a script:

; Register "Click on ListView function"
GUIRegisterMsg($WM_NOTIFY, "MY_WM_NOTIFY")

While 1

; Normal GUIGetMsg() code

; Check if mouse has doubleclicked
    If $fDblClk = True Then
        $fDblClk = False
        ExitLoop    ; You could also put the doubleclicked list code here if you prefer
    EndIf
    
Wend

; Deregister "Click on ListView function"
GUIRegisterMsg($WM_NOTIFY, "")

; Code for doubleclicked list follows here

; -----------

Func MY_WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    
    Local $tNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return
    If DllStructGetData($tNMHDR, 3) = $NM_DBLCLK Then $fDblClk = True
    $tNMHDR = 0
        
EndFunc

I have found this to work well in a number of scripts.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...