TreeView woes

BlitzMax Forums/BlitzMax Programming/TreeView woes

Hi. I finally got around to doing some serious TreeView work and I have a few problems.

If I want the user to rightclick inside an empty treeview and present a popup menu for creating the item what do I do?
I don't seem to get any events when the treeview is empty.

Another problem is that I have to add an item to an item, before I can add more items. Very annoying.
I can't create a treeview with one node named Root for instance, and then just call AddTreeViewNode dynamicall from a menu handler. But if I add a node just after creating the treeview, AddTreeViewNode works. Very odd. Anyone got any ideas? (See code below)

Also notice how the event printing captures no mouseevents (at least not on my system)

Thanks in advance

Example:
' createtreeview.bmx

Strict 

Local window:TGadget=CreateWindow("My Window",50,50,240,240)
Local treeview:TGadget=CreateTreeView(0,0,200,200,window)

SetGadgetLayout treeview,2,2,2,2

Local root:TGadget=TreeViewRoot(treeview)

Global help:TGadget=AddTreeViewNode("Root",root)

Local addNodeMenu:TGadget=CreateMenu("Add node",0,Null)
CreateMenu("Add node", 100, addNodeMenu)

' Comment out below line to have the AddTreeViewNode  in EVENT_MENUACTION stop working!
AddTreeViewNode("Bla", help)


While WaitEvent()
	Print CurrentEvent.ToString()
	Select EventID()
	
		Case EVENT_WINDOWCLOSE
			End
			
		' Item menu?
		Case EVENT_GADGETMENU
		
			' Get selected gadget
			Local selNode:TGadget = SelectedTreeViewNode(treeview)
			
			' Do we need to add a new group?
			If (selNode.text = "Root")
			
				PopupWindowMenu(window,addNodeMenu)
				
			End If
			
		' Menu item selected?
		Case EVENT_MENUACTION
		
			Select EventData()
			
				' Add new group to root?
				Case 100					
																
					AddTreeViewNode("Test node", help)						
			
			End Select

	End Select
Wend



You could do it like this :

' createtreeview.bmx

Strict 

Local window:TGadget=CreateWindow("My Window",50,50,240,240)
Local treeview:TGadget=CreateTreeView(0,0,200,200,window)

SetGadgetLayout treeview,2,2,2,2

Local root:TGadget=TreeViewRoot(treeview)

Global help:TGadget=AddTreeViewNode("Root",root)

Local addNodeMenu:TGadget=CreateMenu("Add node",0,Null)
CreateMenu("Add node", 100, addNodeMenu)
CreateMenu("Add root", 200, addNodeMenu)

' Comment out below line to have the AddTreeViewNode  in EVENT_MENUACTION stop working!
AddTreeViewNode("Bla", help)


While WaitEvent()
	Print CurrentEvent.ToString()
	Select EventID()
	
		Case EVENT_WINDOWCLOSE
			End
			
		' Item menu?
		Case EVENT_GADGETMENU
		
			' Get selected gadget
			Local selNode:TGadget = SelectedTreeViewNode(treeview)
			
			' Do we need to add a new group?
			If (selNode <> Null)
			
				PopupWindowMenu(window,addNodeMenu)
				
			End If
			
		' Menu item selected?
		Case EVENT_MENUACTION
		
			Select EventData()
			
				' Add new group to root?
				Case 100					
																
					AddTreeViewNode("Test node", SelectedTreeViewNode(Root))
					RedrawGadget(Root)	
					
				Case 200 
					
					AddTreeViewNode("Root Extra", Root)					
					RedrawGadget(Root)
			End Select

	End Select
Wend


Yeah I guess that's an ok solution :)