Jump to content
Sign in to follow this  
hamsteren

ListView + contextmenu

Recommended Posts

hamsteren

Hi all,

I want to do the following

i have 1 listview control.

I want to click on an item and i want to have an contextmenu filled with items linked to the item in the Listview i clicked

thnx

Share this post


Link to post
Share on other sites
PaulIA

Hi all,

I want to do the following

i have 1 listview control.

I want to click on an item and i want to have an contextmenu filled with items linked to the item in the Listview i clicked

thnx

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

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  

×