Jump to content

ListView Onevent? Double Click


Recommended Posts

Can someone help give me a kick start with a listview option? I have a list of drives in a listview and I would like to be able to open the drive when I double click on the listview item/drive. I think that it will have something to do with onevent() or something thing like that but I am not familiar with that.

Thanks!

Link to post
Share on other sites
  • Moderators

grasshopper3,

This thread will show how to detect and action a Doublclick in a ListView. ;)

Is that enough of a kick? :)

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

This was helpful, but I am not sure that I am following very well. I also pasted in my listview into the example(attached) in the post and it doesn't work the same. Are there certain styles that it won't work with. For example I am using select entire item

$hListView = GUICtrlCreateListView ("Drive|Device|Status|Share Path|Free Space|Total Space",15,45,560,320,BitOR($LVS_SINGLESEL,$LVS_SHOWSELALWAYS),BitOR($LVS_EX_GRIDLINES,$LVS_EX_CHECKBOXES,$LVS_EX_FULLROWSELECT));

I would like it to be able to open the item/drive when I double click on it.

; If an item was double clicked
    If $fDblClk Then
        $fDblClk = False
        MsgBox(0,'',_GUICtrlListView_GetItemText($hListView ,$aLV_Click_Info[0],2))
;~      Run("Explorer " & _GUICtrlListView_GetItemText($hListView ,$aLV_Click_Info[0],2))
    EndIf

I am not sure how to modify this to make it work for me

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    ; If a combo exists, return immediately
    If $hTmp_Combo <> 0 Then Return $GUI_RUNDEFMSG

    Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hListView And DllStructGetData($tNMHDR, "Code") = $NM_DBLCLK Then
        $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hListView)
        ; As long as the click was on an item or subitem
        If $aLV_Click_Info[0] <> -1 Then $fDblClk = True
    EndIf
    Return $GUI_RUNDEFMSG

EndFunc

new 2.au3

Link to post
Share on other sites
  • Moderators

grasshopper3,

Message handlers are complicated things when you first start out! :)

For the script to work, you need to use the _GUICtrlListView UDF to create the ListView, not the built-in GUICtrlCreateListView. However, I cannot get all the styles to work, even though there is no error.

This gives you the text of the first column when you click on it - which is where you have your drive letter:

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

Opt("TrayIconDebug", 1)

; Set flag to indicate double click in ListView
Global $fDblClk = False
; Declare global variables
Global $aLV_Click_Info

; Open DLL for _IsPressed
$dll = DllOpen("user32.dll")

; Create GUI
$hGUI = GUICreate("Test", 400, 250)

$hListView = _GUICtrlListView_Create($hGUI, "Col 0|Col 1|Col 2", 10, 10, 242, 200)
_GUICtrlListView_AddItem($hListView, "Item 00",0)
_GUICtrlListView_AddSubItem($hListView, 0, "Item 01", 1)
_GUICtrlListView_AddSubItem($hListView, 0, "Item 02", 2)
_GUICtrlListView_AddItem($hListView, "Item 10",1)
_GUICtrlListView_AddSubItem($hListView, 1, "Item 11", 1)
_GUICtrlListView_AddSubItem($hListView, 1, "Item 12", 2)
_GUICtrlListView_AddItem($hListView, "Item 20",2)
_GUICtrlListView_AddSubItem($hListView, 2, "Item 21", 1)
_GUICtrlListView_AddSubItem($hListView, 2, "Item 22", 2)
_GUICtrlListView_AddItem($hListView, "Item 30",3)
_GUICtrlListView_AddSubItem($hListView, 3, "Item 31", 1)
_GUICtrlListView_AddSubItem($hListView, 3, "Item 32", 2)

GUISetState()

; Look for double clicks
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            DllClose($dll)
            Exit
    EndSwitch

    ; If the ListView was double clicked
    If $fDblClk Then
        $fDblClk = False
        Switch $aLV_Click_Info[1]
            Case 0 ; On Item
                $sText = _GUICtrlListView_GetItemText($hListView, $aLV_Click_Info[0])
                MsgBox(0, "", $sText)
        EndSwitch
    EndIf

WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

     Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hListView And DllStructGetData($tNMHDR, "Code") = $NM_DBLCLK Then
        $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hListView)
        ; As long as the click was on an item or subitem
        If $aLV_Click_Info[0] <> -1 Then $fDblClk = True
    EndIf
    Return $GUI_RUNDEFMSG

EndFunc

But as you can see, you do not get checkboxes or gridlines. I will see if I can find anything to solve that. ;)

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

I really appreciate the help!

I didn't use the ListView UDF to create my listview because I wanted the listview to be in a tab display. When I used the UDF it didn't work properly with the tabs plus I couldn't get the styles that I needed.

$Tabs = GUICtrlCreateTab(10,10,575,440)
$ListViewTab = GUICtrlCreateTabItem("ListView")
      $listview = GUICtrlCreateListView ("Drive|Device|Status|Share Path|Free Space|Total Space",15,40,560,310,BitOR($LVS_SINGLESEL,$LVS_SHOWSELALWAYS),BitOR($LVS_EX_FULLROWSELECT,$LVS_EX_GRIDLINES,$LVS_EX_CHECKBOXES))

If you know how to fix that please let me know.

Edited by grasshopper3
Link to post
Share on other sites
  • Moderators

grasshopper3,

Sometimes you just have to accept that certain things are incompatible and go with what you can get! :)

But I will look into the ListView styles problem and see what I can do - no promises, mind. ;)

As to the tab problem, post the code that is posing the problem and we will see what we can do. ;)

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