Jewtus

Double click for Listview

11 posts in this topic

I'm trying to adapt this:

GUIRegisterMsg($WM_LBUTTONDBLCLK, "_WM_LBUTTONDBLCLK")
Local $fDblClk = False
Local $iDoubleClickTime = 200 ; _WinAPI_GetDoubleClickTime() ; 500 by default

Func _WM_LBUTTONDBLCLK($hWnd, $iMsg, $iwParam, $ilParam)
    Local $iX = BitAND($ilParam, 0xFFFF), $iY = BitShift($ilParam, 16)

    $fDblClk = True
    ConsoleWrite("!Double click on: [" & $iX & "," & $iY & "]" & @CRLF)
    Return $GUI_RUNDEFMSG
EndFunc

To work on my List view. I already have a button called $Edit_Btn and I want to make it so when I doubleclick in the list view, it triggers the Edit_Btn case.

The code above seems to print out where I clicked on the console, but only when I click on the GUI background and not on the list view. Is there a easier way to make it so when I double click in a list view, it triggers the edit button?

Share this post


Link to post
Share on other sites



Look in the help file for the function example for _GUICtrlListview_Create, there are a lot of Windows message handler functions in there that can be adapted to your needs.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I took a look, but I'm actually using Guictrlcreatelistview. If I swap it out for _GUICtrlListview_Create, I run into issues. This is what I have:

$List = GUICtrlCreateListView("", 16,45, 546, 278)
_GUICtrlListView_InsertColumn($List, 0, "ID", 150)
_GUICtrlListView_InsertColumn($List, 1, "Name", 250)
_GUICtrlListView_InsertColumn($List, 2, "Description", 150)

and this is what I tried to replace it with:

$DeptList=_GUICtrlListView_Create($FormMain,"ID|Name|Description",16,45, 546, 278,-1, $LVS_EX_TWOCLICKACTIVATE)

When I do that, it breaks my sort function and it also doesn't allow me to select the entire line (just the first column.. which breaks my edit_button because it looks for the selected value then string splits it to get the ID field). 

I also don't think I understand how to trigger the case statement based on the message... I tried this and it didn't work:

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $LVN_ITEMACTIVATE
            MsgBox(0,"TEST","Doubleclicked")

Share this post


Link to post
Share on other sites

Here is a quick Reproducer script
 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>


Local $test[2][3]=[['this','is','a'],['test','test','test']]
$Form1 = GUICreate("Form1", 623, 307, 192, 114)
$List=_GUICtrlListView_Create($Form1,"ID|Name|Description",8, 8, 601, 249,-1, $LVS_EX_TWOCLICKACTIVATE)
_GUICtrlListView_AddArray($List,$test)
_GUICtrlListView_SetColumnWidth($List,0,0)

$Button1 = GUICtrlCreateButton("Button1", 16, 264, 75, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $LVN_ITEMACTIVATE
            MsgBox(0,"TEST","Doubleclicked")
        Case $Button1
            MsgBox(0,"test",StringSplit(_GUICtrlListView_GetItemTextString($List),"|")[1])
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

Jewtus,

I would use a dummy control like this: :)

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

Local $test[2][3] = [['this', 'is', 'a'], ['test', 'test', 'test']]
$Form1 = GUICreate("Form1", 623, 307, 192, 114)
$List = _GUICtrlListView_Create($Form1, "ID|Name|Description", 8, 8, 601, 249, -1, $LVS_EX_TWOCLICKACTIVATE)
_GUICtrlListView_AddArray($List, $test)
_GUICtrlListView_SetColumnWidth($List, 0, 0)

$Button1 = GUICtrlCreateButton("Button1", 16, 264, 75, 25)

; Create a dummy control <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$cDummy = GUICtrlCreateDummy()

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $LVN_ITEMACTIVATE
            MsgBox(0, "TEST", "Doubleclicked")
        ; Add the dummy to the button case <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        Case $Button1, $cDummy
            MsgBox(0, "test", StringSplit(_GUICtrlListView_GetItemTextString($List), "|")[1])
    EndSwitch
WEnd

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    Local $tStruct = DllStructCreate($tagNMHDR, $lParam)
    Local $hWndFrom = DllStructGetData($tStruct, 1)
    Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF)
    If $hWndFrom = $List And $iCode = $NM_DBLCLK Then
        ; Fire the dummy if the ListView is double clicked <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        GUICtrlSendToDummy($cDummy)
    EndIf

EndFunc   ;==>_WM_NOTIFY
All clear? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Melba,

I am actually already using a WM_notify for my sorter... Can you have multiple WM_notifies and call them without interfering with each other? If so, how?

Here is the reproduction script with the other WM_notify:

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

Local $test[2][3] = [['this', 'is', 'a'], ['test', 'test', 'test']]
$Form1 = GUICreate("Form1", 623, 307, 192, 114)
$List = GUICtrlCreateListView("", 5,5, 400, 200)
_GUICtrlListView_InsertColumn($List, 0, "ID", 150)
_GUICtrlListView_InsertColumn($List, 1, "Name", 250)
_GUICtrlListView_InsertColumn($List, 2, "Description", 150)
_GUICtrlListView_AddArray($List, $test)
_GUICtrlListView_SetColumnWidth($List, 0, 0)
$Button1 = GUICtrlCreateButton("Button1", 16, 264, 75, 25)
$cDummy = GUICtrlCreateDummy()
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1, $cDummy
            MsgBox(0, "test", StringSplit(_GUICtrlListView_GetItemTextString($List), "|")[1])
    EndSwitch
WEnd

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    Local $tStruct = DllStructCreate($tagNMHDR, $lParam)
    Local $hWndFrom = DllStructGetData($tStruct, 1)
    Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF)
    If $hWndFrom = $List And $iCode = $NM_DBLCLK Then
        ; Fire the dummy if the ListView is double clicked <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        GUICtrlSendToDummy($cDummy)
    EndIf

EndFunc   ;==>_WM_NOTIFY

;===============================================================================
;
; Function Name:    _ListView_Sort()
; Description:      Sorting ListView items when column click
; Parameter(s):     $cIndex - Column index
; Return Value(s):  None
; Requirement(s):   AutoIt 3.2.12.0 and above
; Author(s):        R.Gilman (a.k.a rasim)
;
; ATTEMPT TO Mod for use with multi list views
;
;================================================================================
Func _ListView_Sort($Listview,$cIndex = 0)
    Local $iColumnsCount, $iDimension, $iItemsCount, $aItemsTemp, $aItemsText, $iCurPos, $iImgSummand, $i, $j

    $iColumnsCount = _GUICtrlListView_GetColumnCount($Listview)

    $iDimension = $iColumnsCount * 2

    $iItemsCount = _GUICtrlListView_GetItemCount($Listview)

    Local $aItemsTemp[1][$iDimension]

    For $i = 0 To $iItemsCount - 1
        $aItemsTemp[0][0] += 1
        ReDim $aItemsTemp[$aItemsTemp[0][0] + 1][$iDimension]

        $aItemsText = _GUICtrlListView_GetItemTextArray($Listview, $i)
        $iImgSummand = $aItemsText[0] - 1

        For $j = 1 To $aItemsText[0]
            $aItemsTemp[$aItemsTemp[0][0]][$j - 1] = $aItemsText[$j]
            $aItemsTemp[$aItemsTemp[0][0]][$j + $iImgSummand] = _GUICtrlListView_GetItemImage($Listview, $i, $j - 1)
        Next
    Next

    $iCurPos = $aItemsTemp[1][$cIndex]
    _ArraySort($aItemsTemp, 0, 1, 0, $cIndex)
    If StringInStr($iCurPos, $aItemsTemp[1][$cIndex]) Then _ArraySort($aItemsTemp, 1, 1, 0, $cIndex)

    For $i = 1 To $aItemsTemp[0][0]
        For $j = 1 To $iColumnsCount
            _GUICtrlListView_SetItemText($Listview, $i - 1, $aItemsTemp[$i][$j - 1], $j - 1)
            _GUICtrlListView_SetItemImage($Listview, $i - 1, $aItemsTemp[$i][$j + $iImgSummand], $j - 1)
        Next
    Next
EndFunc
;================================================================================

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $List
    If Not IsHWnd($List) Then $hWndListView = GUICtrlGetHandle($List)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
    Case $hWndListView
        Switch $iCode
        Case $LVN_COLUMNCLICK
            Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
            Local $ColumnIndex = DllStructGetData($tInfo, "SubItem")
            _ListView_Sort($hWndFrom,$ColumnIndex)
        EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Share this post


Link to post
Share on other sites

Jewtus,

 

Can you have multiple WM_notifies and call them without interfering with each other?

No, but you can just add another case inside the existing handler like this: ;)

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $List
    If Not IsHWnd($List) Then $hWndListView = GUICtrlGetHandle($List)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                
                Case $LVN_COLUMNCLICK
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    Local $ColumnIndex = DllStructGetData($tInfo, "SubItem")
                    _ListView_Sort($hWndFrom,$ColumnIndex)
                    
                Case $NM_DBLCLK
                    ; Fire the dummy if the ListView is double clicked
                    GUICtrlSendToDummy($cDummy)
                    
            EndSwitch
    EndSwitch
            
    Return $GUI_RUNDEFMSG
EndFunc
Now you have everything inside the one handler. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

EXCELLENT!

Melba... Can I send you a gift of some sort? You seem to have all the answers I need  :thumbsup:

Share this post


Link to post
Share on other sites

Jewtus,

My gratitude for the thought but there is no need - the thanks I get here are quite sufficient. :)

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

BTW

 

I took a look, but I'm actually using Guictrlcreatelistview. If I swap it out for _GUICtrlListview_Create, I run into issues. This is what I have:

You don't have to use the UDF Listview with any of those Windows message handlers, all you need is the handle of the Listview.

When I do that, it breaks my sort function and it also doesn't allow me to select the entire line (just the first column.. which breaks my edit_button because it looks for the selected value then string splits it to get the ID field). 

 

I also don't think I understand how to trigger the case statement based on the message... I tried this and it didn't work:


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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