Deselect treeview node

BlitzMax Forums/MaxGUI Bug Reports/Deselect treeview node

I am building a primitive level editor and I have a TreeView that contains all the items that can be placed on the map.

When you select a node, the item that it points to sticks to your mouse and you can place it on the level. When I right-click it releases the item and should deselect the tree node. However, I can't seem to be able to deselect the node.

Any help would be highly appreciated.

Just a guess, but have you tried something like:

SelectTreeViewNode( TreeViewRoot(myTree) )


I did and I get a "Unhandled Exception:Unhandled Memory Exception Error".

I checked to see if the returned node exists and it does, so the error must be somewhere else.

Not nice, but as workaround...

SuperStrict
Import MaxGui.Drivers

Global	TreeView1:TGadget

Local Window1:TGadget = CreateWindow:TGadget("Window1",240,99,150,177,Null,WINDOW_TITLEBAR|WINDOW_RESIZABLE |WINDOW_STATUS |WINDOW_CLIENTCOORDS )
	TreeView1:TGadget = CreateTreeView:TGadget(19,15,107,131,Window1:TGadget,Null)
		AddTreeViewNode( "Item1",TreeViewRoot(TreeView1:TGadget) )
		AddTreeViewNode( "Item2",TreeViewRoot(TreeView1:TGadget) )
		AddTreeViewNode( "Item3",TreeViewRoot(TreeView1:TGadget) )
	Local Button2:TGadget = CreateButton:TGadget("Deselect Treeview",19,152,106,23,Window1:TGadget,BUTTON_PUSH)

Repeat
	WaitEvent()
	Select EventID()
		Case EVENT_WINDOWCLOSE
			Select EventSource()
				Case Window1	Window1_WC( Window1:TGadget )
			End Select

		Case EVENT_GADGETACTION
			Select EventSource()
				Case TreeView1	TreeView1_GA( TreeView1:TGadget, EventExtra:Object() )
				Case Button2	Button2_GA( Button2:TGadget )
			End Select

		Case EVENT_GADGETSELECT
			Select EventSource()
				Case TreeView1	TreeView1_GS( TreeView1:TGadget, EventExtra:Object() )
			End Select

	End Select
Forever

Function Window1_WC( Window:TGadget )
	DebugLog "Window Window1 wants to be closed"

	End
End Function

Function TreeView1_GA( TreeView:TGadget , Node:Object )
	DebugLog "TreeView TreeView1 double clicked a Node"
	
End Function

Function Button2_GA( Button:TGadget )
	DebugLog "Button Button2 was pressed"
	Local Node:TGadget = AddTreeViewNode("",TreeViewRoot(Treeview1))
	FreeTreeViewNode(Node)
End Function

Function TreeView1_GS( TreeView:TGadget , Node:Object )
	DebugLog "TreeView TreeView1 single clicked a Node"
	
End Function



Thanks for the answer. It's an ugly workaround, but it will have to do for now.

Hi,

If you have MinGW installed and set-up correctly, you may like to try the hack below to allow you to deselect an individual node (by selecting the root node instead)...

Open up BlitzMax/mod/maxgui.mod/win32maxguiex.mod/win32maxguiex.bmx and replace the TWindowsTreeNode.Activate() method with...

	Method Activate(cmd)
		Local tmpTree:TWindowsTreeView = TWindowsTreeView(TWindowsGUIDriver.GadgetMap.ValueForKey(String(_tree)))	
		If tmpTree Then tmpTree.Desensitize()
		Select cmd
			Case ACTIVATE_SELECT
				If _item <> TVI_ROOT Then
					SendMessageW _tree,TVM_SELECTITEM,TVGN_CARET,_item
				Else
					SendMessageW _tree,TVM_SELECTITEM,TVGN_CARET,0
				EndIf
			Case ACTIVATE_EXPAND
				SendMessageW _tree,TVM_EXPAND,TVE_EXPAND,_item
				_expanded=True
			Case ACTIVATE_COLLAPSE
				SendMessageW _tree,TVM_EXPAND,TVE_COLLAPSE,_item
				_expanded=False
			Case ACTIVATE_REDRAW
				RedrawNode()
		End Select
		If tmpTree Then tmpTree.Sensitize()
	EndMethod
Next, open up BlitzMax/mod/maxgui.mod/win32maxgui.mod/win32gui/win32treeview.cpp and replace the void Win32TreeViewNode::select() function with...

void Win32TreeViewNode::select(){
	if( _item ) TreeView_SelectItem( _tree, ( _item != TVI_ROOT ? _item : NULL ) );
}
Then save the two files, and run Build Modules from the Program menu in MaxIDE.

Please post to let me know how you get on.

Thanks!

Erm, not really related to this bug, but I can't build the modules anymore for some reason. I'm using Vista x64 and I have installed Visual C++ and VC++ feature package to play with the interface a bit. This might interfere with something, I dunno.

I keep getting "wchar_t*" to "CHAR*" conversion errors. If I go through the files and delete the "L" before strings it's ok, but I really don't wanna go through all the files.

As soon as I get this sorted, I'll try the fix you posted.

another JIM: I think you may have a slightly older version of MaxGUI. I've e-mailed you my latest working copy that you should hopefully have more success with.