Jump to content

OnEvent für ListView


Senten
 Share

Recommended Posts

Hallo zusammen,

ich habe zu dem Thema zwar schon etwas gefunden, konnte dort aber nicht ganz herausfiltern was für mich notwendig und was überflüssig ist. Darum frage ich hier nach dem absoluten Basic zu dem Thema :graduated:

Ich versuche gerade irgendwie einen onEventHandler oder eine GUIMsg für eine ListView zu erstellen. Mein Problem ist, wenn ich solch ein Event über GUICtrlSetOnEvent für die ListView erstelle, reagiert sie nur auf einen Klick auf den Rahmen, nicht auf ein Item. Aber genau das möchte ich, dass das Event ausgelöst wird, sobald ich auf ein ListView-Item klicke.

Vielen Dank im Voraus ;)

Edit: ich würde eine Lösung über die GUI_Msg (Switch/Case) bevorzugen. Danke ^^

Edited by Senten
Link to comment
Share on other sites

Hallo Senten,

this is an english forum, so you should translate your question to english in order to get proper answers. Or place your questions on www.autoit.de - the german community.

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

Hallo Senten,

this is an english forum, so you should translate your question to english in order to get proper answers. Or place your questions on www.autoit.de - the german community.

ooops ^^ sorry i thought i was on autoIT.de xD - So this is the reason why i had to register again ^^'

Ok my question was how i can create an onEvent-Handle for Listview-Items. When I use GUICtrlSetOnEvent the Event only reacts on clicks on the title bars and not on the single items. how can i realize that? Furthermore I would prefer a solution using the GUI_Msg Switch/Case.

Edited by Senten
Link to comment
Share on other sites

  • Moderators

Sentan,

Here is how to detect doubleclicks on ListView items - whether created by the native or UDF commands. ;)

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

; Set flag to indicate double click in ListView
Global $fDblClk = False

$Gui = GUICreate("Test", 400, 250)

; This works with either type of ListView

;#cs
$hListView = GUICtrlCreateListView("Items", 2, 2, 220, 196)
_GUICtrlListView_SetColumnWidth($hListView, 0, $LVSCW_AUTOSIZE_USEHEADER)
GUICtrlCreateListViewItem("Item 1", $hListView)
GUICtrlCreateListViewItem("Item 2", $hListView)
GUICtrlCreateListViewItem("Item", $hListView)
GUICtrlCreateListViewItem("Item 4", $hListView)
;#ce
#cs
$hListView = _GUICtrlListView_Create($Gui, "Items", 2, 2, 220, 196, $LVS_REPORT)
_GUICtrlListView_SetColumnWidth($hListView, 0, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_AddItem($hListView, "Item 1",0)
_GUICtrlListView_AddItem($hListView, "Item 2",2)
_GUICtrlListView_AddItem($hListView, "Item 3",1)
_GUICtrlListView_AddItem($hListView, "Item 4",3)
#ce

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch

    ; If an item was double clicked
    If $fDblClk Then
        $fDblClk = False
        $hWndListView = $hListView
        If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
        ConsoleWrite(_GUICtrlListView_GetItemText($hWndListView, _GUICtrlListView_GetSelectedIndices($hWndListView)) & @CRLF)
    EndIf

WEnd

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

    #forceref $hWnd, $iMsg, $iwParam

    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR

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

    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_DBLCLK
                    $fDblClk = True
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

If you want to detect clicks, just change the $NM_DBLCLK to $NM_CLICK. But I recommend sticking with the doubleclick - the ListView uses single clicks to set the selected item and I have found that the clicks are sometimes eaten and not passed to the handler. :graduated:

If you are not very used to using GUIRegisterMsg, could I recommend the GUIRegisterMsg tutorial in the Wiki. :)

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