MaxGUI: Context menu on treeview

BlitzMax Forums/BlitzMax Beginners Area/MaxGUI: Context menu on treeview

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

You need to create the menu before hand - you don't create it once the event is generated. Have a look at this modified CreateTreeView example that supports right-click.

' createtreeview.bmx

Strict 

Local window:TGadget=CreateWindow("My Window",50,50,400,300)
Local treeview:TGadget=CreateTreeView(0,0,350,250,window)

SetGadgetLayout(treeview,2,2,2,2)

Local root:TGadget=TreeViewRoot(treeview)

Local help:TGadget=AddTreeViewNode("Help",root)
AddTreeViewNode("topic 1",help)
AddTreeViewNode("topic 2",help)
AddTreeViewNode("topic 3",help)

Local projects:TGadget=AddTreeViewNode("Projects",root)
AddTreeViewNode("project 1",projects)
AddTreeViewNode("project 2",projects)
AddTreeViewNode("project 3 is a big waste of time",projects)

Local mnuRightClick:TGadget=CreateMenu("Popup Menu",0,Null)
CreateMenu("Option 1",101,mnuRightClick)
CreateMenu("Option 2",102,mnuRightClick)


Repeat

	Select WaitEvent()
	
		Case EVENT_GADGETMENU;If EventSource() = treeview Then PopupWindowMenu(treeview,mnuRightClick)
	
		Case EVENT_MENUACTION;Local tmpData = EventData();If tmpData = 101 Then Notify("Option 1") ElseIf tmpData = 102 Then Notify("Option 2")
	
		Case EVENT_WINDOWCLOSE;End
		
	End Select

Forever


You then use PopupWindowMenu() to display it once the event is generated.

Seb