I have a problem with a treeview class in my windows form. Specifically I'm try to detect when a user has expanded or contracted a node verses if they have clicked/selected the actual node.
When the user clicks on the node, I want to expand / contract the node to Hide / Show the child nodes (if there are any,) and if there is an associated action trigger it.
So my code goes like this:
Sub SideMenu_MouseClick(sender as Object, e as System.Windows.Forms.TreeNodeMouseClickEventArgs ) Handles SideMenu.MouseClick Dim MyNode As TreeViewNode = e.Node 'here is where the problem occurs if myNode.IsExpanded then myNode.Collapse else myNode.Expand end if Select case trim(MyNode.Keycode) 'Here is where I react to "action" nodes i.e. nodes that trigger actions End Select End Sub
Which works until the user clicks on the +/- box next to a node that has child nodes - The control seams to automatically expand the node then it enters my event code and recollapses or reexpands the node!!
i.e. node 1 is in an unexpanded state the user clicks the expansion button which expands it, then the MouseClick event fires sees that it is already expanded and collapses it.
I've been trying to see if there is a way to capture the button expansion but so far I can only see it happening on MouseClick - Nothing on BeforeSelect, AfterSelect etc. Mouseclick also does not seam to expose the treeviewaction to me to catch if it is Collapse or Expand.