Jump to content
Sign in to follow this  

Getting the correct ListViewItem information

Recommended Posts


Guys & Gals,

I'm pulling out my hair on this and I'm not sure what to do. I have a ListViewItem control and I need to be able to Right click on the item which will bring up a Submenu of choices that I want to perform on the item I clicked on. Yet my script will ONLY return the last item in the list and not the item I clicked on.

Can anyone point out my mistake and educate me on what to do please?

$listview = GUICtrlCreateListView("PC Name|IP", 10, 10, 300, 350, $LVS_SINGLESEL, bitor($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
                GUICtrlSetBkColor($ListView, $GUI_BKCOLOR_LV_ALTERNATE)
                GUICtrlSetBkColor(-1, 0x00CCCC)

            ;$item1 = GUICtrlCreateListViewItem("item2|col22", $listview)

                _SQLite_Startup ()
                _SQLite_Open (@scriptdir & "\database\tgh.db")

                local $hQuery, $sMsg, $aColumn
                Global $PCName
                ;Remember this is SQLITE not SQL so the syntax is different!!!!!!
                _SQlite_Query (-1, "Select * from PcInfo order by Name limit 10 ;", $hQuery) ; the query
                        While _SQLite_FetchData ($hQuery, $aColumn) = $SQLITE_OK
                            $ListViewItem = GUICtrlCreateListViewItem($aColumn[1] & "|" & $aColumn[2], $listview)
                                GUICtrlSetBkColor(-1, 0xffff00)

                                ;GUICtrlSetOnEvent($ListViewItem, "_Test")
                                ;$sMsg &= @CRLF & $aRow[2] & @TAB & @TAB & $aRow[1]

                                ;Right Click Menu
                                $PCName = $aColumn[1]
                                $PCmenu = GUICtrlCreateContextMenu($ListViewItem)
                                    GUICtrlCreateMenuItem("Remote Command Prompt", $PCmenu)
                                    GUICtrlSetOnEvent(-1, "_RemoteCommandPrompt")




Func _RemoteCommandPrompt()
; ===================
  MsgBox(0, "listview item", GUICtrlRead($ListViewItem))
; =====================

Digital Chaos - Life as we know it today.I'm a Think Tank. Problem is, my tank is empty.The Quieter you are, the more you can HearWhich would you choose - Peace without Freedom or Freedom without Peace?Digital Chaos Macgyver ToolkitCompletely Dynamic MenuSQLIte controlsAD FunctionsEXCEL UDFPC / Software Inventory UDFPC / Software Inventory 2GaFrost's Admin Toolkit - My main competitor :)Virtual SystemsVMWAREMicrosoft Virtual PC 2007

Share this post

Link to post
Share on other sites

Here an example:

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

$gui = GUICreate('test')
; === $LVS_EX_FULLROWSELECT required to identify subitem
$hListView = GUICtrlCreateListView('Spalte1|Spalte2', 10, 10, 300, 200, -1, BitOR($LVS_EX_TRACKSELECT,$LVS_EX_FULLROWSELECT))
_GUICtrlListView_SetColumnWidth($hListView, 0, 146)
_GUICtrlListView_SetColumnWidth($hListView, 1, $LVSCW_AUTOSIZE_USEHEADER)
For $i = 1 To 10
    GUICtrlCreateListViewItem('row ' & $i & ' col 1|row ' & $i & ' col 2', $hListView)
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE

Func _RightClick($Info)
    MsgBox(0, 'read row-index ' & $Info[3] & ', col-index ' & $Info[4] , _GUICtrlListView_GetItemText($Info[1], $Info[3], $Info[4]) )

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView
    $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_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    Local $aInfo[5] = [$hWndFrom, _
                                        $iIDFrom, _
                                        $iCode, _
                                        DllStructGetData($tInfo, "Index"), _
                                        DllStructGetData($tInfo, "SubItem")]
EndFunc   ;==>WM_NOTIFY

Best Regards BugFix  

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