Solved

VB.net TreeView adding images by name from resources

Posted on 2012-03-14
3
1,167 Views
Last Modified: 2012-03-16
Hi

I have images in my project resources  that I want to add tol a TreeView
If the resource files are called RED.png BLUE.png and YELLOW.png

How would I add these to certain TreeView nodes
0
Comment
Question by:murbro
3 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37719510
You need to use the ImageList as you have been. Add resources to image list and then use its index in treeview.
0
 
LVL 16

Accepted Solution

by:
Rose Babu earned 500 total points
ID: 37720104
Hi,

assume the below tree structure
- Root
      - Red
      - Blue
      - Yellow

and set the images to the treenodes as like below in your code
'create an ImageList and add the images from the resource files
Dim tvImageList As New ImageList
tvImageList.Images.Add(My.Resources.Red) ' Red.png
tvImageList.Images.Add(My.Resources.Blue) ' Blue.png
tvImageList.Images.Add(My.Resources.Yellow) ' Yellow.png

' Set the imagelist to the treeview
mnuTreeView.ImageList = tvImageList

mnuTreeView.ExpandAll()

'nodRoot - Root Node's name
'nodRed - Red Node's name
'nodBlue - Blue Node's name
'nodYellow - Yellow Node's name

' set the ImageIndex value for the nodes you wanted like below
mnuTreeView.Nodes("nodRoot").ImageIndex = -1 : mnuTreeView.Nodes("nodRoot").SelectedImageIndex = -1

mnuTreeView.Nodes("nodRoot").Nodes("nodRed").ImageIndex = 0 : mnuTreeView.Nodes("nodRoot").Nodes("nodRed").SelectedImageIndex = 0
mnuTreeView.Nodes("nodRoot").Nodes("nodBlue").ImageIndex = 1 : mnuTreeView.Nodes("nodRoot").Nodes("nodBlue").SelectedImageIndex = 1
mnuTreeView.Nodes("nodRoot").Nodes("nodYellow").ImageIndex = 2 : mnuTreeView.Nodes("nodRoot").Nodes("nodYellow").SelectedImageIndex = 2

Open in new window

Try this. It may help you.
0
 

Author Closing Comment

by:murbro
ID: 37728722
Thanks very much
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question