Home - Forums-.NET - FlyTreeView (ASP.NET) - Flytree and Selecting Directory

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

Flytree and Selecting Directory
Link Posted: 27-Nov-2007 06:27
I've loaded the tree with the directory structure of a drive.  The last time the customer was there we saved the path, and now would like to have that path be the selected location, but not the root (they might need to make another selection).

How do we select a child/child folder, and expand to display that entry??
Link Posted: 27-Nov-2007 07:55
Took an hours playing, but have a solution:  Once the nodes are populated call this procedure.
(in the page load event)
If Not IsPostBack Then

    FileSystemNodes.Root_Folder = RootFolder
    FileSystemNodes.AddNodes(FlyTreeView1.Nodes, String.Empty)
    SelectDefaultNode(DailyTransactionFilePathTextBox.Text.Substring(3))
End If


Protected Sub SelectDefaultNode(ByVal aPath As String)

                'walk down the tree examining each of the nodes
  For Each aNode As FlyTreeNode In FlyTreeView1.Nodes

  'if apath has a match in anode. text then we are assuming there is a match, select that node,
  'expand it, and load the child nodes.
    If aPath.IndexOf(aNode.Text) > -1 Then

      'select the node
      aNode.Selected = True
      'expand it.
      aNode.Expanded = True
      'retrieve the child nodes, passing the child nodes of this node, and
      'the full path.
      FileSystemNodes.AddNodes(aNode.ChildNodes, aNode.Path)

      'while there are child nodes, populate them
      Do While aNode.ChildNodes.Count > 0
        'reduce apath to the next entry to prevent duplicates
        aPath = aPath.Substring(aPath.IndexOf("\"))
        'just to show what's happening.
        'MsgBox(aPath & "    " & aNode.path & "   " & aNode.ChildNodes.Count)

        'examine each of the child nodes and look for a match.
        For Each aChildNode As FlyTreeNode In aNode.ChildNodes
          'if we have a match to the path, then select and expand that node.
          'set anode to the current child node, and load the child nodes.
          If aPath.IndexOf(aChildNode.Text) > -1 Then
            aChildNode.Selected = True
            aChildNode.Expanded = True

            'update aNode to be the current child node.
            aNode = aChildNode

            'load the child nodes.
            FileSystemNodes.AddNodes(aNode.ChildNodes, aNode.Path)

            'no reason to examine any more of the path, we have a match.
            Exit For
          End If
        Next

      Loop
      'we are done examining the nodes.
      Exit For
    End If
  Next

  'set foucs to the selected node.
  FlyTreeView1.FocusNode = FlyTreeView1.SelectedNode

End Sub