Sign in to follow this  
Followers 0
d0n

get text of listview after click

3 posts in this topic

How do i get the text of a listview item after i click it?

I know how to get it if i click an extra button

_GUICtrlListView_GetItemText($List1, (_GUICtrlListView_GetSelectedIndices($List1, False) + 0),1)

but i am not sure which function i should use to get it after i click it on the listview

Share this post


Link to post
Share on other sites



How do i get the text of a listview item after i click it?

I know how to get it if i click an extra button

_GUICtrlListView_GetItemText($List1, (_GUICtrlListView_GetSelectedIndices($List1, False) + 0),1)

but i am not sure which function i should use to get it after i click it on the listview

How was the listview created? If it's a native AutoIt control, from GuiCtrlCreateListView(), the you can use standard message loops or event mode:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $listview, $button, $item1, $item2, $item3, $input1, $msg

GUICreate("listview items", 220, 250, 100, 200)

$listview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150);,$LVS_SORTDESCENDING)
$item1 = GUICtrlCreateListViewItem("item1-1|item1-2|item1-3", $listview)
$item2 = GUICtrlCreateListViewItem("item2-1|item2-2|item2-3", $listview)
$item3 = GUICtrlCreateListViewItem("item3-1|item3-2|item3-3", $listview)
$button = GUICtrlCreateButton("Value?", 75, 170, 70, 20)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $listview
            MsgBox(0, "ListView", "Clicked = " & GUICtrlGetState($listview), 2)
        Case $item1, $item2, $item3
            MsgBox(64, "ListViewItem", "Clicked = " & GUICtrlRead(GUICtrlRead($listview)))
    EndSwitch
WEnd

If it's a external GUI or you created the control with _GuiCtrlListView_Create(), then you need to register and handle the WM_NOTIFY message. See the help file example under _GuiCtrlListView_ClickItem().

On second thought, I think Gary did that demo on one of his "Speed with Red Bull chaser" nights! :)

Here's a simplified example:

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

Global $hListView

; Create GUI
GUICreate("ListView Click Item", 400, 300)

; Add listview
$hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
ConsoleWrite("$hListView = " & $hListView & " (" & GUICtrlGetHandle($hListView) & ")" & @LF)

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

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

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

; Handle WM_NOTIFY messages
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $sClickType
    $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
                    $sClickType = "Left Click"
                Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
                    $sClickType = "Left Double-Click"
                Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
                    $sClickType = "Right Click"
                Case $NM_RDBLCLK ; Sent by a list-view control when the user double-clicks an item with the right mouse button
                    $sClickType = "Right Double-Click"
                Case Else ; We aren't interested in other messages
                    Return $GUI_RUNDEFMSG
            EndSwitch
            $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
            ConsoleWrite("WM_NOTIFY: " & $sClickType & @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)
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Try this :

$indexSelected = ControlListView("", "", $LISTVIEW, "GetSelected")
$thisSelected = ControlListView("", "", $LISTVIEW, "GetText", $indexSelected, 0)

Share this post


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
Sign in to follow this  
Followers 0