Sign in to follow this  
Followers 0
gcue

GUICtrlCreateListView, GUICtrlCreateContextMenu, GUICtrlCreateListViewItem and GUICtrlSetOnEvent

11 posts in this topic

#1 ·  Posted (edited)

i have a listview with contextmenuitems which im trying to use guictrlsetonevent with but no response when clicking the menuitems.

i would like to continue usuing guictrlsetonevent instead of gui_getmsg because it's part of a larger script that uses guictrlsetonevent.

any help is appreciated!

$iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)
$iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER)

$user_startup_listview = GUICtrlCreateListView("NAME|PATH", 10, 30, 640, 215, -1, $iExWindowStyle)

_GUICtrlListView_SetColumnWidth($user_startup_listview, 0, 150)
_GUICtrlListView_SetColumnWidth($user_startup_listview, 1, 460)
_GUICtrlListView_SetExtendedListViewStyle($user_startup_listview, $iExListViewStyle)

$item = GUICtrlCreateListViewItem("test|c:\df", $user_startup_listview)
$menu = GUICtrlCreateContextMenu($item)
GUICtrlCreateMenuItem("Find Target", $menu)
GUICtrlSetOnEvent(-1, "StartupPanel_FindTarget")
GUICtrlCreateMenuItem("Delete", $menu)  
GUICtrlSetOnEvent(-1, "StartupPanel_DeleteItem")
Edited by gcue

Share this post


Link to post
Share on other sites



Not sure if this is the problem or just bad copying/pasting but this code is wrong:

GUICtrlCreateMenuItem("Find Target", $menu)
GUICtrlSetOnEvent(-1, "StartupPanel_FindTarget")
GUICtrlSetOnEvent(-1, "StartupPanel_DeleteItem")
GUICtrlCreateMenuItem("Delete", $menu)

It should be:

GUICtrlCreateMenuItem("Find Target", $menu)
GUICtrlSetOnEvent(-1, "StartupPanel_FindTarget")
GUICtrlCreateMenuItem("Delete", $menu)  
GUICtrlSetOnEvent(-1, "StartupPanel_DeleteItem") ;<<<<<<<<<<<<<<<<<<<< moved this line

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

oops sorry yes, bad paste.. still doesnt work though

thx for the heads up! =)

Edited by gcue

Share this post


Link to post
Share on other sites

Shouldn't this line be pointing at the listview and not at the listviewitem you added?

$menu = GUICtrlCreateContextMenu($item) ;~ Shouldn't $item be $user_startup_listview ?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

no because i want the item to carry the menu, not the listview control

Share this post


Link to post
Share on other sites

Aren't the items added in the listview control? What happens when you click on the context menu items? What do those functions they refer to do with the information? Are you sure it's the context menu item events that aren't being handled correctly, or are your functions not handling the information in the listview correctly? Have you tested to see if the functions are called when you click on the context menu item?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

yes they are added to the listview control. but that means ud be able to right click in any whitespace and click "delete this item" - doesnt really apply if you'd be able to do that. that's why id want it to be specific to each listview item. yes i have dummy functions that run msgboxes to indicate they are running properlly. but they are not.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Hello gcue,

i completed your Skript for testing and it works fine:

#Include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
Opt("GuiOnEventMode",1)

GUICreate("Test")
GUISetOnEvent($GUI_EVENT_CLOSE,"_exit")
$iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)
$iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER)

$user_startup_listview = GUICtrlCreateListView("NAME|PATH", 10, 30, 640, 215, -1, $iExWindowStyle)

_GUICtrlListView_SetColumnWidth($user_startup_listview, 0, 150)
_GUICtrlListView_SetColumnWidth($user_startup_listview, 1, 460)
_GUICtrlListView_SetExtendedListViewStyle($user_startup_listview, $iExListViewStyle)

$item = GUICtrlCreateListViewItem("test|c:\df", $user_startup_listview)
$menu = GUICtrlCreateContextMenu($item)
GUICtrlCreateMenuItem("Find Target", $menu)
GUICtrlSetOnEvent(-1, "StartupPanel_FindTarget")
GUICtrlCreateMenuItem("Delete", $menu)
GUICtrlSetOnEvent(-1, "StartupPanel_DeleteItem")
GUISetState()

while 1
    Sleep(250)
WEnd

Func StartupPanel_FindTarget()
    MsgBox(0,"StartupPanel_FindTarget","")
EndFunc

Func StartupPanel_DeleteItem()
    MsgBox(0,"StartupPanel_DeleteItem","")
EndFunc

Func _exit()
    Exit
EndFunc

Remember, you have to use the right Mouse-Button for Contextmenu,

autoBert

Edited by AutoBert

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Hello gcue,

i completed your Skript for testing and it works fine:

#Include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
Opt("GuiOnEventMode",1)

GUICreate("Test")
GUISetOnEvent($GUI_EVENT_CLOSE,"_exit")
$iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)
$iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER)

$user_startup_listview = GUICtrlCreateListView("NAME|PATH", 10, 30, 640, 215, -1, $iExWindowStyle)

_GUICtrlListView_SetColumnWidth($user_startup_listview, 0, 150)
_GUICtrlListView_SetColumnWidth($user_startup_listview, 1, 460)
_GUICtrlListView_SetExtendedListViewStyle($user_startup_listview, $iExListViewStyle)

$item = GUICtrlCreateListViewItem("test|c:\df", $user_startup_listview)
$menu = GUICtrlCreateContextMenu($item)
GUICtrlCreateMenuItem("Find Target", $menu)
GUICtrlSetOnEvent(-1, "StartupPanel_FindTarget")
GUICtrlCreateMenuItem("Delete", $menu)
GUICtrlSetOnEvent(-1, "StartupPanel_DeleteItem")
GUISetState()

while 1
    Sleep(250)
WEnd

Func StartupPanel_FindTarget()
    MsgBox(0,"StartupPanel_FindTarget","")
EndFunc

Func StartupPanel_DeleteItem()
    MsgBox(0,"StartupPanel_DeleteItem","")
EndFunc

Func _exit()
    Exit
EndFunc

Remember, you have to use the right Mouse-Button for Contextmenu,

autoBert

LOL i am.. ur example works for me too - bleh ill have to look closer at mine. thanks! Edited by gcue

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

got it thanks

Edited by drever44

Share this post


Link to post
Share on other sites

ok i got the case part to work will edit the script in earlier post but still want the popup menu to work only on an item in the list view not just any whare.

just had to walk away from it for a few and then relised daaa.

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  
Followers 0