Solved

VB.net TreeView adding images by name from resources

Posted on 2012-03-14
3
1,109 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

810 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