Results 1 to 2 of 2

Thread: [2005] Adding an image to TreeView

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    [2005] Adding an image to TreeView

    Hi Everyone,

    How do I use an image from an ImageList within a TreeView tree? I have figured out how to populate a TreeView, but adding images to the tree is eluding me.

    Any help would greatly be appreciated. Thanks!

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982

    Re: [2005] Adding an image to TreeView

    In your treeview properties window set the imageList property to the imagelist on the form. This will set the ImageIndex property to 0 by default. This causes all the nodes to have the image at index 0 in the imagelist. Set the ImageIndex property to the desired image if you do not want 0 to be the default one.
    Now to have different images for different nodes you set it in code
    VB Code:
    1. TreeView1.Nodes(0).ImageIndex = 1
    Here I am doing it all in code.
    VB Code:
    1. TreeView1.ImageList = imagelist1
    2.     Dim n As New TreeNode
    3.     n.Text = "Hello"
    4.     n.ImageIndex = 1
    5.     TreeView1.Nodes.Add(n)
    Even done this way the image at index 0 in the imagelist is the default for all nodes initially.


    Things I do when I am bored: DotNetable

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