Hi Folks
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 open 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, I can also email you the sample - thanks much !!
Brenda
---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---
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 open 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, I can also email you the sample - thanks much !!
Brenda
---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---