Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2060
Right click select node
posted

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 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:

            treeControl.SelectedNodes.Clear()

            For Each node In GetAllNodesFromTree()

                node.Selected = False

            Next

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?

 

 

 

 

Parents
  • 4618
    Verified Answer
    posted

    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 If
    End 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 K
    Developer Support Engineer
    Infragistics, Inc.
    www.infragistics.com/support

Reply Children
No Data