|
-
Apr 7th, 2004, 10:05 AM
#1
Thread Starter
Member
Is there a better way? Treeview [Resolved]
I have two tables:
tblClassification - id, classification
tblSnipplets - id, classification, title, dateadded, code
I have the key for the treeview classification because I can't use id for some reason. I am having problems when I click on the node I want view the info in some text fields. I think I have the key messed up. Any help would be greatly appreciated.
Thanks
Code:
Private Sub initializeTree()
tvwItems.ImageList = imgList
Dim nodClass As Node
Dim nodTitle As Node
tvwItems.LineStyle = tvwRootLines
tvwItems.Nodes.Clear
'Initialize the recordsets
Set rsClass = New ADODB.Recordset
Set rsTitle = New ADODB.Recordset
'Open the Class recordset
strSQLClass = "SELECT id, classification FROM tblClassification ORDER BY classification"
rsClass.Open strSQLClass, conTree, adOpenStatic, adLockOptimistic
'set node for treeview
If rsClass.RecordCount > 0 Then
While Not rsClass.EOF
Set nodClass = tvwItems.Nodes.Add(, , (rsClass.Fields("classification")), (rsClass.Fields("classification")), 1)
'Opens the recordset for Title
strSQLTitle = "SELECT id, title, classification, code, dateadded FROM tblSnipplets WHERE classification LIKE '" & (rsClass.Fields("classification")) & "%'"
rsTitle.Open strSQLTitle, conTree, adOpenStatic, adLockOptimistic
'set node for treeview
If rsTitle.RecordCount > 0 Then
While Not rsTitle.EOF
Set nodTitle = tvwItems.Nodes.Add((rsClass.Fields("classification")), tvwChild, (rsTitle.Fields("title")), (rsTitle.Fields("title")), 2)
rsTitle.MoveNext
DoEvents
Wend
End If
rsTitle.Close
rsClass.MoveNext
DoEvents
Wend
End If
End Sub
Private Sub tvwItems_NodeClick(ByVal Node As MSComctlLib.Node)
strNodeLabel = Node
If Node.Image = 2 Then
strSQLTitle = "SELECT * FROM tblSnipplets WHERE classification = '" & Me.tvwItems.SelectedItem.Key & "'"
Set rsTitle = New ADODB.Recordset
rsTitle.Open strSQLTitle, conTree, adOpenStatic, adLockOptimistic
showData
Set rsTitle = Nothing
End If
End Sub
Last edited by odamsr; Apr 7th, 2004 at 12:17 PM.
-
Apr 7th, 2004, 12:09 PM
#2
Your code looks fine. What problems are you having?
Do you even need a Key for the Child nodes (or even the parent nodes)? They are not required unless your program has to retrieve the node from the collection using something like
Set objNode = Treeview1.Nodes("SomeKey")
To use a number as a key, you must make sure it contains a character. Such as
nodTitle.Key = "K" & Cstr(rsTitle.Fields("Id").Value
Or you could place the tblSnippets.Id in the Node.Tag property and adjust your code as follows
VB Code:
'...
While Not rsTitle.EOF
Set nodTitle = tvwItems.Nodes.Add((rsClass.Fields("classification")), tvwChild, , (rsTitle.Fields("title")), 2)
nodTitle.Tag = rsTitle.Fields("Id").Value
rsTitle.MoveNext
'...
'in your NodeClick event
If Node.Image = 2 Then
strSQLTitle = "SELECT * FROM tblSnipplets WHERE Id = " & Node.Tag
Set rsTitle = New ADODB.Recordset
'...
-
Apr 7th, 2004, 12:16 PM
#3
Thread Starter
Member
Thanks.. That is what I needed.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|