Sample code for treeview control

How do you code the treeview control?
Who is Participating?
cmgarnettConnect With a Mentor Commented:
Microsoft's example

' Be sure to set References to DAO 3.5
' In the Declarations section, declare module-level
' object variables:
Private mDbBiblio As Database
Private mNode As Node

Private Sub Form_Load()
   ' In Form_Load event, set object variable and
   ' create first Node object of TreeView control.

   Set mDbBiblio = DBEngine.Workspaces(0). _

   tvwDB.Sorted = True
   Set mNode = tvwDB.Nodes.Add()
   mNode.Text = "Publishers"
   mNode.Tag = mDbBiblio.Name   ' Set Tag property.
   mNode.Image = "closed"         ' Set Image    
                                 ' property.
End Sub

Private Sub cmdLoad_Click()
   ' Declare DAO object variables and assign
   ' recordsets to them.
   Dim rsPublishers As Recordset
   Dim rsTitles As Recordset
   Set rsPublishers = mDbBiblio. _
   OpenRecordset("Publishers", dbOpenDynaset)
   Set rsTitles = mDbBiblio. _
   OpenRecordset("titles", dbOpenDynaset)

   ' Go to the first record.

   Dim intIndex As Integer ' Variable for index.

   ' Do until the last record (EOF): add a Node
   ' object and use the Name field as the
   ' new Node object's text.
   Do Until rsPublishers.EOF
      Set mNode = tvwDB.Nodes.Add(1, tvwChild)
      mNode.Text = rsPublishers!Name
      mNode.Tag = "Publisher"   ' Tag identifies the
                                 ' table.
      ' Assign a unique ID to the Key
      mNode.Key = CInt(rsPublishers!PubID) & " ID"
      ' Set the variable intIndex to the Index
      ' property of the newly created Node. Use this
      ' variable to add child Node objects to the
      ' present Node.
      intIndex = mNode.Index
      ' While on this record, search the Title table
      ' for any occurence of the same PubID in the
      ' Titles recordset. If one is found, add a Node
      ' object to the TreeView control, and set the
      ' new Node object properties with the found
      ' record's Title, ISBN and Author fields.
      Do Until rsTitles.EOF
         If rsPublishers!PubID = rsTitles!PubID Then
            Set mNode = tvwDB.Nodes. _
            Add(intIndex, tvwChild)
            mNode.Text = rsTitles!Title   ' Text.
            mNode.Key = rsTitles!ISBN   ' Unique ID.
            mNode.Tag = "Authors"      ' Table name.
            mNode.Image = "leaf"      ' Image.
         End If
      rsTitles.MoveNext ' Next record in Titles.
      ' Reset rsTitles to first Titles record.
      ' Move to next Publisher record.
End Sub

what in particular do u want to do??
All Courses

From novice to tech pro — start learning today.