Results 1 to 2 of 2

Thread: complex treeview

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    1

    complex treeview

    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

  2. #2
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313

    Re: complex treeview

    Hi, welcome VBF!

    How do you want your tree to look?
    Code:
    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?

Posting Permissions

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



Click Here to Expand Forum to Full Width