Skip to content

Selecting a tree’s node in code

New Discussion
richard
richard asked on Mar 23, 2015 8:15 AM

I have a two Ultratree controls…the first tree control is on a form that is restricted in height and width.  So I have a popup component that floats over the form and the height and width is much bigger to all the user to see more detail of the data.  The goal is that when I select a node from the popup form is that it is transfered back to the original form.  I have an event that passes back the selectednodes collection.  I was trying to loop through the orignal tree and have not been able to find anything on how I would programically select the original tree with the same selection from the popup tree.

 

Thanks for any help on this

 

Public Sub SetSelectedNode(ByVal selectedNodes As SelectedNodesCollection)

For Each node As UltraWinTree.UltraTreeNode In selectedNodes

If node.Selected Then

For Each treenode As UltraWinTree.UltraTreeNode In ResultsTree.Nodes

If node.FullPath = treenode.FullPath Then ‘NOTE problem with this is some node paths with the same name.

‘ResultsTree.ActiveNode.Selected = True  ‘NOTE Doesn’t work

‘ResultsTree.Nodes.Item(treenode.Key).Selected = True  ‘NOTE not sure this work plus I don’t have the key set and dont know how.

End If

Next

End If

Next

 

End Sub

 

 

Sign In to post a reply

Replies

  • 0
    Mike Saltzman
    Mike Saltzman answered on Sep 19, 2008 2:46 PM

     [quote user="rrober07"]'ResultsTree.ActiveNode.Selected = True  'NOTE Doesn't work[/quote]

    What exactly is not working? Is the Selected property not return true after you set it? 

    My guess is that your code is working fine, but you just don't see the selected nodes in the tree because the tree does not have focus. Try setting HideSelection on the tree to false or activating the tree control so that you can see the selection. 

    • 0
      richard
      richard answered on Sep 19, 2008 3:45 PM

      Thank you for  your response…

      It did finally work…I reworked my solution below

          Public Sub SetSelectedNode(ByVal selectedNodes As SelectedNodesCollection)

              For Each node As UltraWinTree.UltraTreeNode In selectedNodes
                  If node.Selected Then ResultsTree.Nodes.Item(node.Index).Selected = True
              Next

          End Sub

      Richard

      • 0
        richard
        richard answered on Sep 26, 2008 2:34 PM

        I have been testing this and it works fine when the Rootnode is selected. I doesn't work when a child node is selected.  How can I programically select a child node of the Result tree.  Any ideas?

      • 0
        richard
        richard answered on Sep 26, 2008 3:00 PM

        One more question…How do you make the node expand?…I will keep working on this too…

         

        Thanks,

        Richard

      • 0
        Brian Fallon
        Brian Fallon answered on Sep 26, 2008 3:26 PM

        UltraTreeNode exposes an Expanded property and an ExpandAll method. The former expands only that node, where the latter expands it and all descendants.

      • 0
        richard
        richard answered on Sep 26, 2008 4:25 PM

        Yes that works…one last problem I am having is that even though I am causing the ResultsTree to be selected…It isn't causing the tree to act like it was selected by the user as if they phyically clicked on the ResultsTree.  Is there a method that would cause that action to occur?

        Thanks for you help!

        Richard

      • 0
        Mike Saltzman
        Mike Saltzman answered on Sep 26, 2008 4:47 PM

        Hi Richard,

        What, exactly, is the difference? 

      • 0
        richard
        richard answered on Sep 26, 2008 5:23 PM

        It looks like I figure out my problem:  Here is the code I am using:

        I am having to call the click event of the ResultsTree in code…

            Private Sub FindChild(ByVal parentNode As Infragistics.Win.UltraWinTree.UltraTreeNode, ByVal childNode As Infragistics.Win.UltraWinTree.UltraTreeNode, ByVal selectedNodes As SelectedNodesCollection, ByVal e As System.EventArgs)
                If parentNode.Parent Is Nothing Then
                    For Each node As UltraWinTree.UltraTreeNode In ResultsTree.Nodes(parentNode.Index).Nodes
                        If node.Index = childNode.Index Then
                            ResultsTree.Nodes(parentNode.Index).Expanded = True
                            node.Selected = True
                            _isExpandingCollapse = False
                            If _activateOnSelection Then ResultsTree_Click(selectedNodes, e)
                            Exit For
                        End If
                    Next
                Else
                    FindChild(parentNode.ParentNodesCollection.ParentNode, parentNode, selectedNodes, e)
                End If
            End Sub

    • 0
      Mohit Sabharwal
      Mohit Sabharwal answered on Sep 25, 2013 9:45 AM

      I am not able to select a particular node. Even after setting node.Selected=true, when I check the node.Selected value , it still remains as false

      • 0
        Srikanth Kannebattul
        Srikanth Kannebattul answered on Mar 23, 2015 8:15 AM

        Hi,

        I have a similar issue that I had already a node with the key however trying to add a new node with similar key, not able to find out the existing node with the below info.

        GetNodeByKey(prntNode.Key)

        always it returns false.please help

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
richard
Favorites
0
Replies
10
Created On
Mar 23, 2015
Last Post
11 years ago

Suggested Discussions

Tags

Created by

Created on

Mar 23, 2015 8:15 AM

Last activity on

Feb 23, 2026 4:47 PM