Results 1 to 1 of 1
  1. #1
    Join Date
    Apr 2004
    Posts
    4

    Unanswered: Please help with Treeview

    Hi
    I have a sample with treeview, which is actually designed to display data from the database, what I want to do is to display folders in the treeview and upon selecting a node it should display the files in the listview, the code used in the form is as under, can someone please help me change the code to do what I want to do, the sample is attached. - thanks !!

    ---Code---

    Private Sub Form_Load()

    Dim rst As Recordset
    Dim rstChild As Recordset
    Dim rstGrandChild As Recordset


    Dim db As Database

    Set db = CurrentDb()
    Set rst = db.OpenRecordset("qryParent")

    Dim mNode As Node
    Dim mNodeChild As Node
    Dim mNodeGrandChild As Node

    TreeView.Nodes.Clear

    Do Until rst.EOF
    Set mNode = TreeView.Nodes.Add()
    With mNode
    .Text = rst("Parent")
    .Image = "Closed"
    .SelectedImage = "Open"
    End With

    Set rstChild = db.OpenRecordset( _
    " SELECT * " & _
    " FROM qryChild " & _
    " WHERE Parent ='" & mNode.Text & "'")
    rstChild.MoveFirst

    Do Until rstChild.EOF

    'for each Child record, add a mNodeChild
    Set mNodeChild = TreeView.Nodes.Add( _
    mNode.Index, tvwChild)
    With mNodeChild
    .Text = rstChild("Child")
    .Image = "Closed"
    .SelectedImage = "Open"
    .Tag = "Child"
    End With

    'another child
    Set rstGrandChild = db.OpenRecordset( _
    " SELECT * " & _
    " FROM qryListItems " & _
    " WHERE Parent ='" & mNodeChild.PARENT.Text & "'" & _
    " and Child ='" & mNodeChild.Text & "'")
    rstGrandChild.MoveFirst

    Do Until rstGrandChild.EOF

    'for each Child record, add a mNodeChild
    Set mNodeGrandChild = TreeView.Nodes.Add( _
    mNodeChild.Index, tvwChild)
    With mNodeGrandChild
    .Text = rstGrandChild("ListItem")
    .Image = "Closed"
    .SelectedImage = "Open"
    .Tag = "GrandChild"
    End With

    rstGrandChild.MoveNext
    Loop 'rstgrandchild

    rstChild.MoveNext
    Loop 'rstchild

    rst.MoveNext
    Loop
    End Sub

    Private Sub TreeView_NodeClick(ByVal Node As Object)

    ListView.ListItems.Clear

    Dim db As Database
    Dim rst As Recordset
    Dim mListItem As ListItem
    Set db = CurrentDb()
    Set rst = db.OpenRecordset("SELECT * FROM qryListItems WHERE " & _
    " Parent= '" & Node.PARENT.Text & "' AND " & _
    " Child= '" & Node.Text & "'")
    rst.MoveFirst
    Do Until rst.EOF
    Set mListItem = ListView.ListItems.Add()
    With mListItem
    .Text = rst("ListItem")
    .SmallIcon = "ListItem"
    .SubItems(1) = rst("Detail1")
    .SubItems(2) = rst("Detail2")
    End With

    rst.MoveNext
    Loop


    End Sub

    ---Code---
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •