MaxGUI: Context menu on treeview

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

Is it possible to right-click on a tree node and get a contextual menu?

I've got...
	WaitEvent()
	
	Select EventID()
		Case EVENT_GADGETMENU
			Select EventSource()
				Case tree
					Local popupmenu:TGadget = CreateMenu("popup_tree", 0, tree)
					CreateMenu("Add...", POPUPMENU_ADD, popupmenu)
					CreateMenu("Remove", POPUPMENU_REMOVE, popupmenu)
					PopupWindowMenu(tree, popupmenu)
			EndSelect
		
		Case EVENT_MENUACTION
			Select EventData()					
				Case POPUPMENU_ADD
					Local current_node:TGadget = SelectedTreeViewNode(tree)
					AddTreeViewNode("Added", current_node)
				
				Case POPUPMENU_REMOVE
					Local current_node:TGadget = SelectedTreeViewNode(tree)
					FreeTreeViewNode(current_node)
			End Select


I want to be able to right-click on a node to Add a new branch to the tree or remove a node (and hence all the branches derived from it), but it doesn't seem to work as expected. What am I doing wrong?

see this thread, http://www.blitzmax.com/Community/posts.php?topic=56725#630731
hth

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

@assari: That link appears to be broken for me. I just get "ERROR: Internal Error". :(

...

Ah, got it now. Cheers!

same with me, but that was because he is logged in www.blitzmax.com, im logged into www.blitzbasic.com....nvm