PDA

Click to See Complete Forum and Search --> : complex treeview


smttools
Jun 2nd, 2005, 08:52 AM
Hi, I'm trying to create a form using the treeview control . I know how to polpulate a simple tree view but this one is too complicated for me to work out.

My data is arranged like this:

CategoryID|v_categories_name_1|v_categories_name_2|v_categories_name_3|v_categories_name_4|v_categor ies_name_5

126|Hardware|Abrasive Products|Sanding Rolls|Aluminium Oxide|100mm X 50m
127|Hardware|Abrasive Products|Sanding Rolls|Aluminium Oxide|115mm X 10m

If someone knows of an example to download then please help, Cheers for looking

This is the code I have so far:

Sub Buildbranch(Optional varParentID As Variant)
On Error Resume Next

Dim oTree As TreeView, nodCurrent As Node
Dim Db As DAO.Database
Dim rstCat1 As DAO.Recordset
Dim rstSub As DAO.Recordset
Dim strText As String
Dim strKey As String
Dim intNum As Integer

Set oTree = Me!TreeCtl.Object

strText = "Categories"
strKey = "rootNode"
Set nodCurrent = oTree.Nodes.Add(, , strKey, strText)

Set Db = CurrentDb()
Set rstCat1 = Db.OpenRecordset("SELECT DISTINCT tblCat.v_categories_name_1 FROM tblCat;", dbOpenDynaset)

rstCat1.MoveFirst
Do Until rstCat1.EOF
strText = rstCat1!v_categories_name_1
strKey = "A_" & rstCat1!CategoryID
intNum = rstCat1!CategoryID

Set nodCurrent = oTree.Nodes.Add("rootNode", tvwChild, strKey, strText)
'Loop thru all other categories
rstCat1.MoveNext
Loop

End Sub

PilgrimPete
Jun 7th, 2005, 07:40 AM
Hi, welcome VBF!

How do you want your tree to look?

Hardware
Abrasive Products
Sanding Rolls
Aluminium Oxide
100mm X 50m
100mm X 10m
Next sanding roll type
100mm X 50m
100mm X 10m
Next abrasive product type
...

If so, then we have two ways of achieving it - hardcoding 5 categories to store the type each time, or writing a more generic recursive routine to handle multiple categories.
Also, do you want to build the tree entirely on load, or only as each node is clicked?
Is the database format fixed, or do you have control over it - i.e. can it be normalised a bit?