Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.net TreeView adding images by name from resources

Posted on 2012-03-14
3
Medium Priority
?
1,322 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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:Murray Brown
ID: 37728722
Thanks very much
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 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