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!
Printable View
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!
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
Here I am doing it all in code.VB Code:
TreeView1.Nodes(0).ImageIndex = 1Even done this way the image at index 0 in the imagelist is the default for all nodes initially.VB Code:
TreeView1.ImageList = imagelist1 Dim n As New TreeNode n.Text = "Hello" n.ImageIndex = 1 TreeView1.Nodes.Add(n)