Jump to content

Need help: I want to use right mouse click on listview


Recommended Posts

Thanks, i did this yesterday and the menu popup appeared.

now i want to now, how can i read the selected item in the listview ?

i want to right click on an item and get information about it.

Here is an example of how to do this using Auto3Lib:

#include <A3LListView.au3>
#include <A3LMenu.au3>

Global Const $tagNMITEMACTIVATE = "int WndFrom;int IDFrom;int Code;int Item;int SubItem;int NewState;int OldState;int Changed;" & _
             "int PointX;int PointY;int Param;int KeyFlags"

; Global variables
Global $hGUI, $hList

; Create GUI
$hGUI  = GUICreate("ListView", 400, 300)
$hList = _ListView_Create($hGUI, 2, 2, 396, 296)
GUISetState()

; Add columns
_ListView_AddColumn($hList, "Column 1", 100)
_ListView_AddColumn($hList, "Column 2", 100)
_ListView_AddColumn($hList, "Column 3", 100)

; Add items
_ListView_AddItem   ($hList,    "Row 1: Col 1", 0)
_ListView_AddSubItem($hList, 0, "Row 1: Col 1", 1)
_ListView_AddSubItem($hList, 0, "Row 1: Col 2", 2)
_ListView_AddItem   ($hList,    "Row 2: Col 1", 1)
_ListView_AddSubItem($hList, 1, "Row 2: Col 1", 1)
_ListView_AddItem   ($hList,    "Row 3: Col 1", 2)

; Loop until user exits
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
do
until GUIGetMsg() = $GUI_EVENT_CLOSE

; Handle WM_NOTIFY messages
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
  Local $tItem, $iCode, $aItem, $hMenu

  $tItem = DllStructCreate ($tagNMITEMACTIVATE, $ilParam)
  $iCode = DllStructGetData($tItem, "Code")
  if $iCode = $NM_RCLICK then
    $aItem = _ListView_SubItemHitTest($hList)
    if $aItem[0] <> -1 then
      $hMenu = _Menu_CreatePopup()
      _Menu_AddMenuItem($hMenu, "Item " & $aItem[0] & ": SubItem " & $aItem[1] & " Open", 1000)
      _Menu_AddMenuItem($hMenu, "Item " & $aItem[0] & ": SubItem " & $aItem[1] & " Save", 1001)
      _Menu_TrackPopupMenu($hMenu, $hGUI)
      _Menu_DestroyMenu($hMenu)
    endif
  endif
  Return $GUI_RUNDEFMSG
EndFunc
Auto3Lib: A library of over 1200 functions for AutoIt
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...