Jump to content

List View Double Click annoyance


momar33
 Share

Recommended Posts

Run the code below and you will see that the double click works fine on the list view items.

Now double click below the list view items.

You will see that a message box will come up with a value of 0.

I would like any double click that is not on an item to do nothing

Is this possible?

; Simple Example of WM Notify
#include <GUIConstants.au3>
;#include <A3LTreeView.au3>
#include <GuiTab.au3>

Global $main_GUI,$ok_button,$cancel_button

; This window has 2 ok/cancel-buttons
$main_GUI  = GUICreate("TAB in TAB",260,250,-1,-1)
    
    $listview        = GUICtrlCreateListView("Col1|Col2",10,10,210,150)
                    GUICtrlCreateListViewItem("ItemLong1|ItemLong12", $listview)
                    GUICtrlCreateListViewItem("ItemLong2|Item22", $listview)
        
    $ok_button        = GUICtrlCreateButton("OK",40,220,70,20)
    $cancel_button    = GUICtrlCreateButton("Cancel",150,220,70,20)

GUISetState()

;; Insert this to catch events
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[0]
        Case $GUI_EVENT_CLOSE, $cancel_button
            ExitLoop
    EndSwitch
WEnd

;; Insert this to handle events
Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
     #forceref $hWndGUI, $MsgID, $wParam
     Local $tagNMHDR, $event, $hwndFrom, $code
     $tagNMHDR = DllStructCreate("int;int;int", $lParam)
     If @error Then Return
     $event = DllStructGetData($tagNMHDR, 3)
     Select
     Case $wParam = $ListView
          Select
               Case $event = $NM_DBLCLK
                    msgbox(0,"",GUICtrlRead(GUICtrlRead($listview),1))
            EndSelect
    EndSelect
endFunc
Link to comment
Share on other sites

instead of:

msgbox(0,"",GUICtrlRead(GUICtrlRead($listview),1))

use:

$text = _GUICtrlListView_GetItemText($ListView, _GUICtrlListView_GetNextItem($ListView),1); current selected
    If $text = -1 Then msgbox(0,"",$text)

EDIT: correct is

$text = _GUICtrlListView_GetItemText($ListView, _GUICtrlListView_GetNextItem($ListView),1); current selected
    If $text <> -1 Then msgbox(0,"",$text)
Edited by Zedna
Link to comment
Share on other sites

Hi,

#include <GUIConstants.au3>
#include <GuiTab.au3>
#include <GuiListView.au3>

Global $main_GUI, $hListView, $ok_button, $cancel_button, $OnItem

; This window has 2 ok/cancel-buttons
$main_GUI  = GUICreate("TAB in TAB",260,250,-1,-1)
$hListView = GUICtrlCreateListView("Col1|Col2",10,10,210,150)
GUICtrlCreateListViewItem("ItemLong1|ItemLong12", $hListView)
GUICtrlCreateListViewItem("ItemLong2|Item22", $hListView)
$ok_button = GUICtrlCreateButton("OK",40,220,70,20)
$cancel_button = GUICtrlCreateButton("Cancel",150,220,70,20)
GUISetState()

;; Insert this to catch events
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE, $cancel_button
            ExitLoop
        Case $ok_button
            ;;;Do whatever
        Case Else
            If $OnItem Then
                msgbox(0,"",GUICtrlRead(GUICtrlRead($hListView),1))
                $OnItem = 0
            EndIf   
    EndSwitch
WEnd

;; Insert this to handle events
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_DBLCLK
                    $aHit = _GUICtrlListView_HitTest($hWndListView)
                    If $aHit[5] Then $OnItem = 1 
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Cheers

Edited by smashly
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...