Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Having Icons in Treeview AX ctrl (2003)

    Hello people,

    I'm using a MIcrosoft's Treeview ActiveX Object to populate another view of my contacts database. Everything works good, but how do I put little icons in front of the items - just like in windows explorer?

    I tried using an Image List Object to choose that image list from the Properties Tab of the TreeCtrl, but the images I selected just give me blanks in the actual treeview.

    Please tell me how to have lil icons in front of items in treeview. Thanks.

    Dennis

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Having Icons in Treeview AX ctrl (2003)

    Make sure that
    a) you have set the Style property of the TreeView control to 1, 3, 5 or 7, and
    [img]/forums/images/smilies/cool.gif[/img] that you have set the ImageList property to the name of your ImageList control (you must set this property by right-clicking the TreeView and selecting TreeCtrl Object | Properties from the popup menu.)

    Specify the index of the icon when you add nodes, here is an example from one of my databases:

    tvwTreeView.Nodes.Add parentNodeKey, tvwChild, sNodeKey, sNodeText, 2

    tvwTreeView is the TreView control.
    parentNodeKey is the key of the parent of the node to be added.
    sNodeKey is the key of the node to be added
    sNodeText is the text to be displayed
    2 is the index in the ImageList control of the image to be displayed (1 = first, 2 = second etc.)

  3. #3
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Having Icons in Treeview AX ctrl (2003)

    This is how my code looks:

    <pre> Set dbs = CurrentDb()
    strQuery1 = "qryEBookAuthors"
    strQuery2 = "qryEBooksByAuthor"

    With Me![tvwBooks]
    'Fill Level 1
    Set rst = dbs.OpenRecordset(strQuery1, dbOpenForwardOnly)

    'Add a node object for each record in the "qryEBookAuthors" table/query.
    'The Key argument concatenates the level number and the LastNameFirst
    'field of the Level 1 query, to create a unique key value for the node.
    'The Text argument is the text displayed as a Level 1 node in the
    'TreeView control

    Do Until rst.EOF
    strNode1Text = StrConv("Level1" & rst![LastNameFirst], _
    vbLowerCase)
    Set nod = .Nodes.Add(Key:=strNode1Text, Text:=rst![LastNameFirst])
    'Expand the entire node
    nod.Expanded = True
    rst.MoveNext
    Loop
    rst.Close

    'Fill Level 2
    Set rst = dbs.OpenRecordset(strQuery2, dbOpenForwardOnly)

    'Add a node object for each record in the "qryEBooksByAuthor"
    'table/query.
    'The value of the Relative argument matches the Key argument value
    'for the Level 1 node this Level 2 node belongs to.
    'The Relationship argument takes a named constant, tvwChild,
    'indicating that the Level 2 node becomes a child node of the
    'Level 1 node named in the Relative argument.
    'The Key argument concatenates the level number and the Title
    'field of the Level 2 query, to create a unique key value for the node.
    'The Text argument is the text displayed as a Level 2 node in the
    'TreeView control

    Do Until rst.EOF
    strNode1Text = StrConv("Level1" & rst![LastNameFirst], vbLowerCase)
    strNode2Text = StrConv("Level2" & rst![Title], vbLowerCase)
    strVisibleText = rst![Title]
    .Nodes.Add relative:=strNode1Text, _
    relationship:=tvwChild, _
    Key:=strNode2Text, _
    Text:=strVisibleText
    rst.MoveNext
    Loop
    rst.Close

    End With
    dbs.Close</pre>



    I think I have to add that ", index" to this line
    Set nod = .Nodes.Add(Key:=strNode1Text, Text:=rst![LastNameFirst]) but everytime I try to add it Access gives me an error.
    Since there are no references in the helpfile, I gotta come back to you...

    Dennis

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Having Icons in Treeview AX ctrl (2003)

    The documentation for the TreeView control can be found on MSDN:
    General: Using the TreeView Control (Visual Basic 6)
    Reference: TreeView Control
    Nodes.Add: Add Method (Nodes Collection)

    You'd use something like

    Set nod = .Nodes.Add(Key:=strNode1Text, Text:=rst![LastNameFirst], Image:=2)

  5. #5
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Having Icons in Treeview AX ctrl (2003)

    Thanks for your information and your help. Works

    Dennis

Posting Permissions

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