Jump to content
Sign in to follow this  
scon

treeviewitem and contextmenu problem

Recommended Posts

scon

HI!

Help me, please.

I try to use treeview in my program. But there is a problem: rightclick does not set selection on treeviewitem, and I cannot receive for processing chosen treeviewitem handler. How to choose treeviewitem through rightclick?

#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>

$i = 0
Opt("GUIOnEventMode", 1)


$iStyle = BitOR( $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)

GUICreate("Test", 300, 370)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE")
$hTreeView = GUICtrlCreateTreeView(2, 2, 296, 368, $iStyle, $WS_EX_CLIENTEDGE)

$context = GUICtrlCreateContextMenu($hTreeView)
$buttonitem = GUICtrlCreateMenuItem("Right_Click", $context)


GUICtrlSetOnEvent(-1, "MenuEvents")




$d1 = _GUICtrlTreeView_InsertItem($hTreeView, "bla-bla 1", "" )
$d2 = _GUICtrlTreeView_InsertItem($hTreeView, "bla-bla 2", "" )
$d3 = _GUICtrlTreeView_InsertItem($hTreeView, "bla-bla 3", "" )
$d4 = _GUICtrlTreeView_InsertItem($hTreeView, "bla-bla 4", "" )



   
    
GUISetState()


Do
sleep(10)
Until $i > 0


Func MenuEvents()
Msgbox(64,$buttonitem, _GUICtrlTreeView_GetText($hTreeView, _GUICtrlTreeView_GetSelection  ($hTreeView)))
EndFunc

Func CLOSE()
Exit
EndFunc

Sorry for my bad Eng

TNX

Edited by scon

Share this post


Link to post
Share on other sites
scon

Thanks. The problem was resolved. Theme is closed :)

Help! How i can get handle of treeviewitem to Func MenuSelect() ??

#include <GuiConstants.au3>
#include <GuiTreeView.au3>
#include "ModernMenuRaw.au3"





Opt("GuiOnEventMode", 1)

Global $TreeItems[111][2]
$TreeItems[0][0] = 100



$hGui = GUICreate("TreeView context menu", 400, 400)
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")



$iTreeView = GUICtrlCreateTreeView(10, 10, 380, 340)
GUICtrlSetOnEvent(-1, "MenuSelect")


$TreeViewItem1 = GUICtrlCreateTreeViewItem("All numbers", $iTreeView)


For $i = 1 To $TreeItems[0][0]

$s = random (1)
    $TreeItems[$i][0] = GUICtrlCreateTreeViewItem($s, $TreeViewItem1)
    $NickMenu = GUICtrlCreateContextMenu($TreeItems[$i][0])

_GUICtrlCreateODMenuItem($s, $NickMenu)
GUICtrlSetOnEvent(-1, "MenuSelect")

_GUICtrlCreateODMenuItem("menu item", $NickMenu)
GUICtrlSetOnEvent(-1, "MenuSelect")

Next


GUISetState()

While 1
Sleep(10)
WEnd

Func Quit()
Exit
EndFunc

Func MenuSelect()
msgbox(64, _GUICtrlTreeView_GetSelection($iTreeView), "", 2) ; ???????
EndFunc
Edited by scon

Share this post


Link to post
Share on other sites
scon

I can solve the problem if I can transfer a variable in function MenuSelect():

_GUICtrlCreateODMenuItem("first menu item", $NickMenu)
$var = "zxcvb"
GUICtrlSetOnEvent(-1, "MenuSelect")

_GUICtrlCreateODMenuItem("menu item second", $NickMenu)
$var = "12345"
GUICtrlSetOnEvent(-1, "MenuSelect")

_GUICtrlCreateODMenuItem("just menu item", $NickMenu)
$var = "abcdef"
GUICtrlSetOnEvent(-1, "MenuSelect")
...
...
Func MenuSelect($var)
...
EndFunc

How to send $var together with event in Func MenuSelect?

Please help me ;)

Edited by scon

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  

×