Jump to content

How to get events directly on ListViewItem


Loc
 Share

Recommended Posts

I have 2 Listview, Listview 1 has item now I want to get event from that item to add to listview 2 by itself, I already have examples of how to add the same name and increase the quantity. Let me ask how to double click on item on listview1 and it will appear on listview 2 :( . Ca

;This is my code
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

$hGUI = GUICreate("Sell", 320, 500, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP))
$List1 = GUICtrlCreateListView("Product|Amount|Money", 8, 0, 300, 230, _
        BitOR($GUI_SS_DEFAULT_LISTVIEW, $LVS_AUTOARRANGE, $LVS_NOSORTHEADER, $WS_VSCROLL), _
        BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150)
GUICtrlCreateListViewItem("Cake|1|10.000", $List1)
GUICtrlCreateListViewItem("Cooking|1|10.000", $List1)
GUICtrlCreateListViewItem("Street|1|10.000", $List1)
GUICtrlCreateListViewItem("Salt|1|10.000", $List1)
$List2 = GUICtrlCreateListView("Product|Amount|Money", 8, 235, 300, 230, _
        BitOR($GUI_SS_DEFAULT_LISTVIEW, $LVS_AUTOARRANGE, $LVS_NOSORTHEADER, $WS_VSCROLL), _
        BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150)
GUISetState()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

n you give me a simple example or keyword for me to search also :(

Untitled.png

Link to comment
Share on other sites

Goldenix pasted a script, in this thread, on how to make the doubleclicks on listviews.

 

Alternatively you can look on this script:

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

Local $test[5][2] = [['.au3', 'AutoIt'], ['.ahk', 'Auto Hotkey'], ['.txt', 'text'],['.sdlbas', 'Sdl Basic'], ['.html', 'Webpage']]
$Form1 = GUICreate("Create New File", 210, 307, -1,-1, $WS_CAPTION , $WS_EX_TOOLWINDOW)
$List = GUICtrlCreateListView("", 5,5, 200, 200)
_GUICtrlListView_InsertColumn($List, 0, "Extension", 80)
_GUICtrlListView_InsertColumn($List, 1, "Name", 130)
_GUICtrlListView_AddArray($List, $test)

$Button1 = GUICtrlCreateButton("Ok", 16, 214, 45, 26)
$Button2 = GUICtrlCreateButton("Cancel", 140, 214, 45, 26)
$cDummy = GUICtrlCreateDummy()
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Button2
            Exit
        Case $Button1, $cDummy
            local $tmptxt=StringSplit(_GUICtrlListView_GetItemTextString($List), "|")[1]
            if StringLen($tmptxt)>0 then
                MsgBox(0, "test", $tmptxt)
            EndIf
    EndSwitch
WEnd

;================================================================================
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $List
    If Not IsHWnd($List) Then $hWndListView = GUICtrlGetHandle($List)

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

    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode

                Case $NM_DBLCLK
                    ; Fire the dummy if the ListView is double clicked
                    GUICtrlSendToDummy($cDummy)

            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc

 

Here is a hint, if you want to try it by yourself: The help file contains many functions and examples.

To get a string and all subitems, from one LV, you can use 

_GUICtrlListView_GetItemTextString()

or use these two commands, to copy the items directly 

_GUICtrlListView_SetItemSelected($idListview, $x)
_GUICtrlListView_CopyItems($idListview, $idListview1)

 

Edited by Dan_555

Some of my script sourcecode

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