Advertisement
Guest User

Adam Bachman

a guest
Jun 1st, 2008
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.20 KB | None | 0 0
  1. ''' <summary>
  2. ''' Fill treeMap Dictionary with collection of TreeNodes.
  3. ''' </summary>
  4. ''' <param name="treeMap"></param>
  5. ''' <remarks></remarks>
  6. Public Shared Sub BuildTree(ByRef treeMap As Dictionary(Of String, TreeNode))
  7.     ' Build Tree Menu
  8.     Dim ds As DataSet = GetMenuItems()
  9.     Dim rootNode As New TreeNode("Manufacturing Documentation", "11")
  10.     '' Root document has ID 11 in the DB.
  11.     rootNode.ImageUrl = "images/folder.png"
  12.     rootNode.NavigateUrl = "Document.aspx?doc=11&parent=0"
  13.     treeMap("11") = rootNode
  14.     For Each row As DataRow In ds.Tables(0).Rows
  15.         Dim nodeId As String = row("nodeId")
  16.         Dim parentId As String = row("parentId")
  17.         Dim title As String = row("title")
  18.         Dim _desc As Object = row("description")
  19.         Dim desc As String = ""
  20.         If Not _desc Is Nothing Then
  21.             desc = _desc.ToString()
  22.         End If
  23.  
  24.         If treeMap.ContainsKey(nodeId) Then
  25.             treeMap(nodeId).Text = title
  26.             treeMap(nodeId).Value = nodeId
  27.             treeMap(nodeId).NavigateUrl = _
  28.                 String.Format("Document.aspx?doc={0}&parent={1}", nodeId, parentId)
  29.         Else
  30.             treeMap(nodeId) = New TreeNode(title, nodeId)
  31.             treeMap(nodeId).Expanded = False
  32.             treeMap(nodeId).NavigateUrl = _
  33.                 String.Format("Document.aspx?doc={0}&parent={1}", nodeId, parentId)
  34.             If desc = "folder" Then
  35.                 treeMap(nodeId).ImageUrl = "images/folder.png"
  36.             End If
  37.         End If
  38.  
  39.         If Not treeMap.ContainsKey(parentId) Then
  40.             treeMap(parentId) = New TreeNode()
  41.             treeMap(parentId).Expanded = False
  42.         End If
  43.         treeMap(parentId).ChildNodes.Add(treeMap(nodeId))
  44.     Next
  45.  
  46.     ' Set the NavigateUrl for each parent node (folder) to the first child document.  This
  47.     ' will open the folder and avoid dead pages (links to non-document objects).
  48.     'For Each node As String In treeMap.Keys
  49.     '    If treeMap(node).ChildNodes.Count > 0 Then
  50.     '        treeMap(node).NavigateUrl = String.Format("Document.aspx?doc={0}&parent={1}", treeMap(node).ChildNodes(0).Value, node)
  51.     '    End If
  52.     'Next
  53.  
  54.     ds.Dispose()
  55. End Sub
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement