Hi
I've been trying to use this code to ensure a node is selected when I right click on it (in this case so that the context menu is shown for the correct node):
Private Sub ProcessHierarchyTree_MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles ProcessHierarchyTree.MouseClick
If e.Button = MouseButtons.Right Then
Dim treeControl As UltraTree = TryCast(sender, UltraTree)
Dim nodeAtPoint As UltraTreeNode = treeControl.GetNodeFromPoint(e.Location)
If nodeAtPoint IsNot Nothing Then
treeControl.SelectedNodes.Clear()
For Each node In GetAllNodesFromTree()
node.Selected = False
Next
nodeAtPoint.Selected = True
End If
End Sub
This does select the node, but it also leaves the previous node still selected. This is doubly odd as I have treeview set on single select. I have this code in the control's constructor:
Me.ProcessHierarchyTree.HideSelection = False
Me.ProcessHierarchyTree.Override.SelectionType = SelectType.Single
I've also tried adding:
But this didn't sort it either.
Any thoughts on how I can get the previously item to no longer be selected? Or any settings I might have set that are stopping this working as expected?
Perfect! Many thanks.
Hi redox,
It appears that in your sample the node is selected, but is not actually being activated; this condition leaves the first node in an active state, even though you have selected an entirely different node.
Under normal user interaction with the UltraTree, when a node is clicked on with the left mouse button, it is both selected and also activated. Since you are modifying this selection behavior, you will also need to activate the selected node during the MouseClick event.
I have provided a code snippet below to provide further context for this implementation.
Private Sub ultraTree1_MouseClick(sender As Object, e As MouseEventArgs) If e.Button = MouseButtons.Right Then Dim node As UltraTreeNode = ultraTree1.GetNodeFromPoint(e.Location)
If node IsNot Nothing Then node.Selected = True ultraTree1.ActiveNode = node End If End IfEnd Sub
If you have any further questions at all regarding this solution or if I may be of any further assistance, please let me know.
Sincerely,Chris KDeveloper Support EngineerInfragistics, Inc.www.infragistics.com/support