Click in Listbox - Beispiel gesucht

  • Hi,

    ich suche ein Beispiel für den Click in der Listbox, um den Inhalt auszugeben.
    Die Beispiele, die ich gefunden habe sind von 2006 und 2007 und da stimmen leider die Befehle nicht mehr. :(

    In dem Beispiel aus der Hilfe wird mir über den Button der korrekte Zeilenwert angezeigt. Ich hätte den Wert aber gerne beim Klick auf der Zelle.

    Spoiler anzeigen


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

    Opt('MustDeclareVars', 1)

    Example()

    Func Example()
    Local $listview, $button, $item1, $item2, $item3, $input1, $msg

    GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
    GUISetBkColor(0x00E0FFFF) ; will change background color

    $listview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 150);,$LVS_SORTDESCENDING)
    $button = GUICtrlCreateButton("Value?", 75, 170, 70, 20)
    $item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview)
    $item2 = GUICtrlCreateListViewItem("item1|col12|col13", $listview)
    $item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview)
    $input1 = GUICtrlCreateInput("", 20, 200, 150)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping
    GUISetState()

    Do
    $msg = GUIGetMsg()

    Select
    Case $msg = $button
    MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)), 5)
    Case $msg = $listview
    MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 5)
    EndSelect
    Until $msg = $GUI_EVENT_CLOSE
    EndFunc ;==>Example


    Grüße und Danke
    Guido

  • Hallo Greenhorn,

    Danke für den Tipp.
    Das Beispiel konnte ich soweit erweitern, das mir der Text der Zelle angezeigt wird.
    Für die Forumsuche der optimierte Code. :)

    Gibt es einen Trick damit beim Spoiler nicht die Einrückungen verloren gehen?

    Spoiler anzeigen


    #AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
    #include <GuiConstantsEx.au3>
    #include <GuiListView.au3>
    #include <GuiStatusBar.au3>
    #include <GuiImageList.au3>
    #include <WindowsConstants.au3>

    Opt('MustDeclareVars', 1)

    $Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

    Global $hListView, $StatusBar, $iIndex = -1, $iSubIndex = -1

    _Main()

    Func _Main()
    Local $hImage, $GUI

    ; Create GUI
    $GUI = GUICreate("ListView SubItem Hit Test", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    $hListView = GUICtrlGetHandle($hListView) ; get the handle for use in the notify events
    $StatusBar = _GUICtrlStatusBar_Create($GUI, -1, "")

    ; Enable extended control styles
    _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_SUBITEMIMAGES)
    GUISetState()

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    ; Load images
    $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 16, 16))
    _GUICtrlListView_SetImageList($hListView, $hImage, 1)

    ; Add columns
    _GUICtrlListView_AddColumn($hListView, "Column 1", 100)
    _GUICtrlListView_AddColumn($hListView, "Column 2", 100)
    _GUICtrlListView_AddColumn($hListView, "Column 3", 100)

    ; Add items
    _GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
    _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1, 1)
    _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2, 2)
    _GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1)
    _GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1, 2)
    _GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2)

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
    EndFunc ;==>_Main

    Func ListView_Click()
    Local $aHit
    local $text

    $aHit = _GUICtrlListView_SubItemHitTest($hListView)
    If ($aHit[0] <> -1) And (($aHit[0] <> $iIndex) Or ($aHit[1] <> $iSubIndex)) Then
    _GUICtrlStatusBar_SetText($StatusBar, @TAB & StringFormat("HitTest Item: %d, SubItem: %d", $aHit[0], $aHit[1]))
    $iIndex = $aHit[0]
    $iSubIndex = $aHit[1]
    $text = _GUICtrlListView_GetItemText($hListView, $iIndex,$iSubIndex)
    MsgBox(4096,"-",$text)
    EndIf
    EndFunc ;==>ListView_Click

    Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $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_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
    ListView_Click()
    ; No return value
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY