Adding Nodes to Treeview Control:   Return to List

TreeView1.Visible = False
TreeView1.Nodes.Clear
MyQuickSort_Tri aryCodeList(), LBound(aryCodeList(), 2), UBound(aryCodeList(), 2), 1, 2, 3, True
For i = LBound(aryCodeList(), 2) To UBound(aryCodeList(), 2)
    ' Add base node if not already present
    strNewLang = aryCodeList(1, i)
    If strNewLang <> strOldLang Then
        ' Build a unique key
        lngKeyCount = lngKeyCount + 1
        strLangKey = BuildKey(lngKeyCount, 1)
        ' Ensure text doesn't exceed 30 chars
        strKeyText = strNewLang
        If Len(strKeyText) > 60 Then
            strKeyText = Left(strKeyText, 60)
        End If
        ' Add the new node -- at base
        frmSnippetBrowser.Visible = False
        Set xNod = TreeView1.Nodes.Add(, , strLangKey, strKeyText)
        strOldLang = strNewLang
    End If
    ' Add Category if not already present
    strNewCat = aryCodeList(2, i)
    If strNewCat <> strOldCat Then
        ' Build a unique key
        lngKeyCount = lngKeyCount + 1
        strCatKey = BuildKey(lngKeyCount, 2)
        ' Ensure text doesn't exceed 30 chars
        strKeyText = strNewCat
        If Len(strKeyText) > 60 Then
            strKeyText = Left(strKeyText, 60)
        End If
        ' Add the new node -- below appropriate lang
        Set xNod = TreeView1.Nodes.Add(strLangKey, tvwChild, strCatKey, strKeyText)
        strOldCat = strNewCat
    End If
    ' Add description node beneath applicable category
    ' Make the key the ID number -- so we can use it to access the code
    strDescription = aryCodeList(3, i)
    strID = aryCodeList(0, i)
    intID = Val(strID)
    strKeyText = BuildKey(intID, 3)
    Set xNod = TreeView1.Nodes.Add(strCatKey, tvwChild, strKeyText, strDescription)
Next
For i = 1 To TreeView1.Nodes.Count
    TreeView1.Nodes.Item(i).Expanded = True
Next
' Note number of children in text
Dim intChild As Integer
For i = 1 To TreeView1.Nodes.Count
    strText = TreeView1.Nodes.Item(i).Text
    intChild = Val(TreeView1.Nodes.Item(i).Children)
    If intChild > 0 Then
        strText = strText & " (" & LTrim(Str(intChild)) & ")"
        TreeView1.Nodes.Item(i).Text = strText
    End If
Next
TreeView1.Nodes.Item(1).EnsureVisible ' Repositions at the top
TreeView1.Visible = True

' All nodes in a Treeview have 2 basic properties:
    Node.Text -- The text displayed in the Treeview control
    Node.Key -- The assigned key -- used to attach children & perform other manipulations on the particular node.

See also:
Treeview ... Adding Root Node
Treeview ... Collapsing Nodes to Root Level
Treeview ... Complete Subprocedure for Collapsing Nodes
Treeview ... Counting Number of Nodes
Treeview ... Expanding All Nodes
Treeview ... Determing selected Node and Highlighting it
Treeview ... ChildNode Info of Selected Node
Treeview ... Text of Selected Node
Treeview ... Node Click Event
Treeview ... Number of Children (in parens) appended to Text of Selected Node
Treeview ... Reacting to DragOver in a Treeview
Treeview ... Reacting to Drag and Drop
Treeview ... Repositioning Cursor to the Top of the Treeview



Note to Webmaster