Solved

VB.net TreeView adding images by name from resources

Posted on 2012-03-14
3
1,038 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks very much
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now