MadaraUchiha Posted December 4, 2013 Posted December 4, 2013 Hi, Just a quick question. I have a contextmenu on my listview, where i can select options for my items, works all fine. But it also pops up if there are 0 items. I only want it to popup when there are 1 or more items in the listview. How? Is there something like an opening event for the contextmenu? :/
l3ill Posted December 4, 2013 Posted December 4, 2013 Something like: $var = _GUICtrlListView_GetItemCount If $var >0 Then GuiCreateContextMenu Func Endif Might work... My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
Moderators Melba23 Posted December 4, 2013 Moderators Posted December 4, 2013 MadaraUchiha,There might well be a better way - but this seems to work quite well: expandcollapse popup#include <GUIConstantsEx.au3> #include <Constants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> Global $mCM_1 = 0, $mCM_2 = 0, $fFlag_1 = False, $fFlag_2 = False, $mItem_1 = 9999, $mItem_2 = 9999 $hGUI = GUICreate("Test", 500, 500) $cLV_1 = GUICtrlCreateListView(" ", 10, 10, 230, 240) GUICtrlCreateListViewItem("Item 1", $cLV_1) $cLV_2 = GUICtrlCreateListView(" ", 260, 10, 230, 240) GUISetState() GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $mItem_1 MsgBox($MB_SYSTEMMODAL, "Menu", "ListView 1 context menu actioned") Case $mItem_2 MsgBox($MB_SYSTEMMODAL, "Menu", "ListView 2 context menu actioned") EndSwitch ; Look for flags If $fFlag_1 Then ; Clear flag $fFlag_1 = False ; Right click on LV_1 ControlClick($hGUI, "", $cLV_1, "right") EndIf If $fFlag_2 Then $fFlag_2 = False ControlClick($hGUI, "", $cLV_2, "right") EndIf WEnd Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) Local $iCode = DllStructGetData($tNMHDR, "Code") Switch $iCode Case $NM_RCLICK ; Check if a ListView has sent the message Switch $hWndFrom Case GUICtrlGetHandle($cLV_1) ; Get item count If _GUICtrlListView_GetItemCount($cLV_1) Then If $mCM_1 = 0 Then ; Create menu if required $mCM_1 = GUICtrlCreateContextMenu( $cLV_1) $mItem_1 = GUICtrlCreateMenuItem("Test 1", $mCM_1) ; Set flag $fFlag_1 = True EndIf Else ; Destroy any existing menu GUICtrlDelete($mCM_1) ; Placeholders $mCM_1 = 0 $mItem_1 = 9999 EndIf Case GUICtrlGetHandle($cLV_2) If _GUICtrlListView_GetItemCount($cLV_2) Then If $mCM_2 = 0 Then $mCM_2 = GUICtrlCreateContextMenu( $cLV_2) $mItem_2 = GUICtrlCreateMenuItem("Test 1", $mCM_2) GUICtrlCreateMenuItem("text", $mItem_2) $fFlag_2 = True EndIf Else GUICtrlDelete($mCM_2) $mCM_2 = 0 $mItem_2 = 9999 EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFuncPlease ask if you have any questions. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now