+ Reply to Thread
Results 1 to 4 of 4

TreeView Image List

  1. #1
    mark
    Guest

    TreeView Image List

    Hi.

    I'm basically new to TreeView, though I have tried it before, a long time ago.

    I found a short example about adding nodes, referencing them to parents,
    etc...

    I see that you can add images to the nodes, but in order to do it, you need
    to first have an imagelist associated with the treeview.

    Which in turn means that you have to instantiated an image list, and
    populated it with images.

    There's the question... how do I work with an image list and images... I
    couldn't seem to find it in the available controls, though they are both
    there for dimensioning in the code.

    Thanks for any help with this.

  2. #2
    Forum Contributor
    Join Date
    12-11-2004
    MS-Off Ver
    2007
    Posts
    137
    Hello Mark



    these examples are used to change the images when you select a node in the treeview
    ( it use 2 images or icons )




    if you insert the images or icon manually in the imageList before run the UserForm

    Private Sub UserForm_Initialize()
    Dim k As Byte, j As Byte
    Set Me.TreeView1.ImageList = Me.ImageList1

    For k = 1 To 5
    TreeView1.Nodes.Add , , "maClé1" & k, "ParentNode" & k, _
    ImageList1.ListImages(1).Key, ImageList1.ListImages(2).Key
    Next

    For j = 1 To 5
    For k = TreeView1.Nodes.Count To TreeView1.Nodes.Count + 2
    TreeView1.Nodes.Add "maClé1" & j, tvwChild, "maClé2" & Str(k), "ChildNode" & k, _
    ImageList1.ListImages(1).Key, ImageList1.ListImages(2).Key
    Next
    Next
    End Sub





    if the pictures or icons are stored on the PC , you may use


    Private Sub UserForm_Initialize()
    Dim k As Byte, j As Byte
    Dim Img1 As String, Img2 As String

    Me.ImageList1.ListImages.Clear

    Img1 = ThisWorkbook.Path & "\LeChat.bmp"
    Img2 = ThisWorkbook.Path & "\2053851.jpg"
    Me.ImageList1.ListImages.Add 1, "Image1", LoadPicture(Img1)
    Me.ImageList1.ListImages.Add 2, "Image2", LoadPicture(Img2)

    Set Me.TreeView1.ImageList = Me.ImageList1

    For k = 1 To 5
    TreeView1.Nodes.Add , , "maClé1" & k, "ParentNode" & k, "Image1", "Image2"
    ComboBox1.AddItem "ParentNode" & k
    Next

    For j = 1 To 5
    For k = TreeView1.Nodes.Count To TreeView1.Nodes.Count + 2
    TreeView1.Nodes.Add "maClé1" & j, tvwChild, "maClé2" & Str(k), "ChildNode" & k, "Image1", "Image2"
    ComboBox1.AddItem "ChildNode" & k
    Next
    Next
    End Sub


    another example
    http://www.excel-downloads.com/html/...397_127397.htm
    http://www.excel-downloads.com/html/...s_TreeView.zip


    I hope this help you

    Regards ,
    michel

  3. #3
    Robert Bruce
    Guest

    Re: TreeView Image List

    Roedd <<mark>> wedi ysgrifennu:


    > There's the question... how do I work with an image list and
    > images... I couldn't seem to find it in the available controls,
    > though they are both there for dimensioning in the code.
    >


    Right-click on your controls toolbox to add a new control. From the list,
    pick Microsoft ImageList (might be version 5 or 6 depending on which version
    of VB you have installed). You can then add this control to your form.
    Select the control once it is on your form's surface and set its properties
    (including adding images) via the (Custom)[...] section of the properties
    window.

    Once you have added some images, you will find that you can't bind your
    treeview to your imagelist at design time. I suspect that this is because
    the two controls were not designed to be used with MSForms (and/or vice
    versa). So, you'll have to bind at run time -

    Private Sub UserForm_Initialize()
    Set Me.TreeView1.ImageList = Me.ImageList1
    Me.TreeView1.Nodes.Add , , , "My Node", 1, 2
    Me.TreeView1.Nodes.Add , , , "My Other Node", 1, 2
    'etc...
    End Sub

    You should be aware that to use this control in Office (except for Access)
    you will need a design time licence for every machine it runs on. In other
    words, you are not allowed to distribute Excel apps built with the treeview
    and/or the imageview control.

    --
    Rob

    http://www.asta51.dsl.pipex.com/webcam/

    This message is copyright Robert Bruce and intended
    for distribution only via NNTP.
    Dissemination via third party Web forums with the
    exception of Google Groups and Microsoft Communities
    is strictly prohibited and may result in legal action.



  4. #4
    mark
    Guest

    Re: TreeView Image List

    > You should be aware that to use this control in Office (except for Access)
    > you will need a design time licence for every machine it runs on. In other
    > words, you are not allowed to distribute Excel apps built with the treeview
    > and/or the imageview control.




    Thanks for telling me about that.

    I use two machines here at work... one has Visual Basic 6, and the other
    does not. The one that does not have VB6 does have MS Access 2000. Is that
    why the treeview and imagelist controls are available on the machine without
    VB?

    Question... how would one be supposed to know that distributing Excel apps
    with the treeview and imagelist is inappropriate, when it is available and
    works from Excel, without any warnings about illegality? I didn't know.
    (and haven't done it yet).

    Mark




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1