Treeview Control

W

Working2Hard

I have been looking all over the internet trying to find some example of code
that simplifys the treeview control. The Best one that i found was on the
microsoft support site and it went something like this.

Private Sub Form_Load()

Dim CN As ADODB.Connection, RS As ADODB.Recordset
Dim RS2 As ADODB.Recordset
Dim RS3 As ADODB.Recordset
Dim RS4 As ADODB.Recordset


Set CN = CurrentProject.Connection
Set RS = New ADODB.Recordset
Set RS2 = New ADODB.Recordset
Set RS3 = New ADODB.Recordset
Set RS4 = New ADODB.Recordset


'open a recordset and loop through it to fill the Treeview Control
RS.Open "TreeControl", CN, adOpenForwardOnly

Do Until RS.EOF
Me!axTreeView.Nodes.Add , , RS!UniqueID, RS!Lvl1
RS.MoveNext
Loop
RS.Close


' Fill Level 2

RS.Open "TreeControl", CN, adOpenForwardOnly
RS2.Open "TreeControlLvl2", CN, adOpenForwardOnly
Do Until RS.EOF
StrOrderKey = StrConv(RS!Lvl1, vbLowerCase)
Me!axTreeView.Nodes.Add RS!UniqueID.Value, tvwChild, StrOrderKey,
RS2!Lvl2
RS.MoveNext
Loop
RS.Close
RS2.Close


' Fill level 3

RS.Open "TreeControl", CN, adOpenForwardOnly
RS2.Open "TreeControlLvl2", CN, adOpenForwardOnly
RS3.Open "TreeControlLvl3", CN, adOpenForwardOnly
Do Until RS.EOF
StrOrderKey = StrConv(RS!Lvl1, vbLowerCase)
StrProductId = StrConv(StrOrderKey & RS2!Lvl2, vbLowerCase)
Me!axTreeView.Nodes.Add StrOrderKey, tvwChild, StrProductId,
RS3!Lvl3
RS.MoveNext
Loop
RS.Close
RS2.Close
RS3.Close


' Fill level 4

RS.Open "TreeControl", CN, adOpenForwardOnly
RS2.Open "TreeControlLvl2", CN, adOpenForwardOnly
RS3.Open "TreeControlLvl3", CN, adOpenForwardOnly
RS4.Open "TreeControlLvl4", CN, adOpenForwardOnly
Do Until RS.EOF
StrOrderKey = StrConv(RS!Lvl1, vbLowerCase)
StrProductId = StrConv(StrOrderKey & RS2!Lvl2, vbLowerCase)
StrLvl4 = StrConv(StrProductId & RS3!Lvl3, vbLowerCase)
Me!axTreeView.Nodes.Add StrProductId, tvwChild, StrLvl4, RS4!Lvl4
RS.MoveNext
RS2.MoveNext
RS3.MoveNext
RS4.MoveNext
Loop
RS.Close
RS2.Close
RS3.Close
RS4.Close

CN.Close
Set RS = Nothing
Set CN = Nothing


End Sub


I have had a play with the code and cant work out why i cant get it to
display more that 1 item per level

e.g.
what I get:

Standards
-----Lvl1
-------Lvl2

What I want:

Standards
-----Lvl1
-------Lvl2
Lvl2a
Lvl2b

Any suggestions?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top