Jump to content

ListviewEX and double click

Recommended Posts

Hello Autoit Team

I have a listview and it works fine. But there is a problem, i want handle double click to the "0" index coloum (when I double click to this coloums I want open another form). Is there a way ?

Coloumn 1 and 2 are ok

Can Someone help me ?

This is the example code:




Link to post
Share on other sites
  • Moderators


You can do it like this:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include "GUIListViewEx.au3"
#include <Array.au3>

Global $lw_col2 = 0xCECBCE
Global $lw_col1 = 0xADAAAD

$hGUI = GUICreate("Example Listview", 600, 300)

$lw_Example = GUICtrlCreateListView("", 10, 10, 500, 280, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS))

_GUICtrlListView_SetExtendedListViewStyle($lw_Example, $LVS_EX_FULLROWSELECT)

_GUICtrlListView_AddColumn($lw_Example, "ID", 40) ;0
_GUICtrlListView_AddColumn($lw_Example, "COL1", 138) ;1
_GUICtrlListView_AddColumn($lw_Example, "COL2", 300) ;2

_GUICtrlListView_SetBkColor($lw_Example, $lw_col1)
_GUICtrlListView_SetTextColor($lw_Example, $CLR_BLACK)
_GUICtrlListView_SetTextBkColor($lw_Example, $lw_col1)

GUICtrlSetFont($lw_Example, 11, 400, 1)

$iCurrentColor_lw_Example = $lw_col2
For $i = 0 To 20

    $sRecord = "0" & "|"
    $sRecord &= "list" & "|"
    $sRecord &= $i & "|"

    $ctrItemListview_Func = GUICtrlCreateListViewItem($sRecord, $lw_Example)

    If $iCurrentColor_lw_Example = $lw_col2 Then
        $iCurrentColor_lw_Example = $lw_col1
        $iCurrentColor_lw_Example = $lw_col2
    GUICtrlSetBkColor($ctrItemListview_Func, $iCurrentColor_lw_Example)

$iListviewIndex_lw_Example = _GUIListViewEx_Init($lw_Example, "", 1, 0xFFFFFF, False, 512)

; Get funtion handle
Local $hFunc = _MyFunc
; Set column to use mode 9
_GUIListViewEx_SetEditStatus($iListviewIndex_lw_Example, 0, 9, $hFunc)
_GUIListViewEx_SetEditStatus($iListviewIndex_lw_Example, 1, 1)
_GUIListViewEx_SetEditStatus($iListviewIndex_lw_Example, 2, 2, "Choice1|Choice2|Choice3", True)

_GUIListViewEx_EditWidth($iListviewIndex_lw_Example, 400)



While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE


    $vRet = _GUIListViewEx_EventMonitor(0) ; Use combos to change EditMode
    Switch @extended
        Case 0
            ; No event detected
        Case 1
            If $vRet = "" Then
                MsgBox($MB_SYSTEMMODAL, "Edit", "Edit aborted" & @CRLF)
                _ArrayDisplay($vRet, "ListView " & _GUIListViewEx_GetActive() & " content edited", Default, 8)
        Case 2
            If $vRet = "" Then
                MsgBox($MB_SYSTEMMODAL, "Header edit", "Header edit aborted" & @CRLF)
                _ArrayDisplay($vRet, "ListView " & _GUIListViewEx_GetActive() & " header edited", Default, 8)
        Case 3
            MsgBox($MB_SYSTEMMODAL, "Sorted", "ListView: " & $vRet & @CRLF)
        Case 4
            MsgBox($MB_SYSTEMMODAL, "Dragged", "From : To" & @CRLF & $vRet & @CRLF)


; And here is the function - note you need all 4 parameters even if you do not need them
Func _MyFunc($hLV, $iLVIndex, $iRow, $iCol)

    MsgBox($MB_SYSTEMMODAL, "Column One clicked", "Row = " & $iRow)


All clear?


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:


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 post
Share on other sites

Another way :

;;; the above code goes here
;;; edit the line to
;;; add this line
;;; below code goes here
;;; add this function
Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
  Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
  Local $hLV = DllStructGetData($tStruct, 1)
  Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF)
  If $hLV = GUICtrlGetHandle ($lw_Example) And $iCode = $NM_DBLCLK Then
    $iRow = DllStructGetData($tStruct, 4)
    $iCol = DllStructGetData($tStruct, 5)
    If $iCol = 0 Then
      ConsoleWrite("double click " & $iRow & "/" & $iCol & @CRLF)
      ; call your function here
      ; Return 1 ; that will depends what your are doing, but this will cause to stop the message chain
  Return _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_WM_NOTIFY

But to be honest M23 solution is simpler ;)

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...