Case CurrentSelected_ListViewItem usw.

  • Hej,

    mein heutiges Problem liegt darin, das ich nicht weiß wie ich einer Case-Abfrage das zurzeit angeklickte Item herausfinde. Man soll in einem ListView auf ein Item klicken können und dann soll, erstmal nur testhalber, der Text aus dem Item in einer MsgBox ausgegeben werden. Die Anzahl der Items ändert sich im Script aber ständig. Da ich mit _GUICtrlListView_AddItem neue dazuerstelle und mit _GUICtrlListView_DeleteAllItems wieder lösche. Dazu kommt ebenfalls noch, das jedes mit _GUICtrlListView_AddItem erstellte Item noch ein Subitem bekommt (_GUICtrlListView_AddSubItem). Ich hab leider keine Ahnung wie soetwas lösen könnte, vielleicht Ihr ;)

    Danke schomal,
    Lg Jautois

    Einmal editiert, zuletzt von Jautois (5. Juni 2009 um 21:08)

    • Offizieller Beitrag

    Probiers mal mit der Funktion _GUICtrlListView_GetSelectedIndices

  • Sowas?

    [autoit]


    ;
    ;
    GUIRegisterMsg($WM_NOTIFY, "_DoubleClickOnListView")
    ;
    ;

    [/autoit][autoit][/autoit][autoit]

    Func _DoubleClickOnListView($hWnd, $Msg, $wParam, $lParam) ;Doppelklick auf ein Listviewitem
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return
    $event = DllStructGetData($tagNMHDR, 3); Checkt wie das EVENT aussieht
    If $wParam = $hListView and $event = $NM_DBLCLK Then ;Wenn der Klick auf das ListView ging und es ein Doppelklick ($NM_CLICK = einfacher Klick - s Windows constants). war, dann
    ;deine Funktion
    EndIf
    $tagNMHDR = 0
    $event = 0
    $lParam = 0
    EndFunc ;==>_DoubleClickOnListView

    [/autoit]

    P.S. Fairerweise muss man dazu sagen das die Funktion nicht von mir ist :)

    edit \ durch den Klick wird ja ein Items dann ausgewählt.
    mit _GUICtrlListView_GetSelectionMark würde ich dann weitermachen!

  • So funktioniert es auch ;)

    Spoiler anzeigen
    [autoit]

    #include <GuiImageList.au3>
    #include <GuiStatusbar.au3>
    #include <GUIListView.au3>
    #include <File.au3>

    [/autoit] [autoit][/autoit] [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <ListViewConstants.au3>
    #include <ProgressConstants.au3>
    #include <EditConstants.au3>
    #include <StatusBarConstants.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)
    #Region ### START Koda GUI section ### Form=D:\Dokumente\Dateien von Andreas\AutoIt3\FTP\GUI_MAIN.kxf
    Global $GUI_MAIN = GUICreate("Au3FTP", 882, 586, 193, 125)
    GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_MAINClose")

    [/autoit] [autoit][/autoit] [autoit]

    Global $ListView1 = GUICtrlCreateListView("Name|Datum|Größe", 8, 48, 369, 489)
    GUICtrlCreateListViewItem("Test|12|12",$ListView1)
    GUICtrlCreateListViewItem("Test|23231|324235345",$ListView1)
    Global $hListView1 = GUICtrlGetHandle($ListView1)

    [/autoit] [autoit][/autoit] [autoit]

    $LvDblClick = GUICtrlCreateDummy()
    GUICtrlSetOnEvent($LvDblClick, "_LVDblClick")

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit]

    Func _LVDblClick()
    MsgBox(0, '', "Item #" & GUICtrlRead(@GUI_CtrlId) & " wurde geklickt")
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func GUI_MAINClose()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(100)
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo

    [/autoit] [autoit][/autoit] [autoit]

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $hListView1
    Switch $iCode

    [/autoit] [autoit][/autoit] [autoit]

    Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
    ConsoleWrite("+++++++++++++++++++++++++++++++++++++++++++++++++++" & @LF & "$NM_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
    "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
    "-->Code:" & @TAB & $iCode & @LF & _
    "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _
    "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
    "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
    "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
    "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
    "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
    "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
    "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _
    "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags") & @LF & _
    "+++++++++++++++++++++++++++++++++++++++++++++++++++" & @LF)
    GUICtrlSendToDummy($LvDblClick, DllStructGetData($tInfo, "Index")) ;
    ; No return value
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit]
  • Danke an Euch drei! Werde mir die Codes bzw. Funktionen direktmal anschaun. Ich melde mich, wenn ich erfolgreich bin :P

    Edit: Habe mir alle angeschaut. Der Code von nuts, gefällt mir gut, da er recht kurz ist.

    Nun habe ich dazu aber noch eine Frage: Wie bekomme ich nun den Text, des angeklickten Items?

    Einmal editiert, zuletzt von Jautois (5. Juni 2009 um 21:50)

  • Einfach Index durch eine der 3 Funktionen rausbekommen und dann ebn-> _GUICtrlListView_GetItemText

    Also ungefähr so ->

    Spoiler anzeigen
    [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)
    #Region ### START Koda GUI section ### Form=D:\Dokumente\Dateien von Andreas\AutoIt3\FTP\GUI_MAIN.kxf
    Global $GUI_MAIN = GUICreate("Au3FTP", 882, 586, 193, 125)
    GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_MAINClose")

    [/autoit] [autoit][/autoit] [autoit]

    Global $ListView1 = GUICtrlCreateListView("Name|Datum|Größe", 8, 48, 369, 489)
    GUICtrlCreateListViewItem("Test1|12|12",$ListView1)
    GUICtrlCreateListViewItem("Test2|23231|324235345",$ListView1)
    Global $hListView1 = GUICtrlGetHandle($ListView1)

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit]

    Func GUI_MAINClose()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(100)
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo

    [/autoit] [autoit][/autoit] [autoit]

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $hListView1
    Switch $iCode
    Case $NM_DBLCLK
    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
    MsgBox(0,"",_GUICtrlListView_GetItemText($hListView1,DllStructGetData($tInfo, "Index")))
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit]

    Einmal editiert, zuletzt von ChaosKeks (5. Juni 2009 um 22:20)

  • Danke! Ich hab es mal so gemacht:

    [autoit]


    Func _DoubleClickOnListView($hWnd, $Msg, $wParam, $lParam)
    Local $tagNMHDR, $event
    $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return
    $event = DllStructGetData($tagNMHDR, 3)
    If $wParam = $ListView1 and $event = $NM_DBLCLK Then
    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
    MsgBox(1,"",_GUICtrlListView_GetItemText($ListView1,DllStructGetData($tInfo, "Index"),DllStructGetData($tInfo, "SubItem")))
    EndIf
    EndFunc ;==>_DoubleClickOnListView

    [/autoit]