?
Solved

VB.net assign image to TreeView node by name

Posted on 2012-04-06
4
Medium Priority
?
636 Views
Last Modified: 2012-04-06
I have to load a TreeView's images from an array of image names (not indexes). Is it possible to load an image from resources to a TreeView node?
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
  • 2
  • 2
4 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 37816575
The images need to be in an ImageList for use with the TreeView.  You could load up the images from the resources into an ImageList at run-time, and associate each Name with the correct Index using a Dictionary.

Do the images really need to be resources though?...why not just load them directly into an ImageList?
0
 

Author Comment

by:Murray Brown
ID: 37816632
Hi. Thanks. You are right. They don't need to be in resources. I just realised that they are actually held in a folder, How do you associate each name with a dictionary? Thanks
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 37816654
You could actually do something really simple like this using a String Array:
Public Class Form1

    Private ImageNames() As String = {"cat", "dog", "fish"}

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim index As Integer = Array.IndexOf(ImageNames, "dog")
        ' ... use "index" with your ImageList ...
    End Sub

End Class

Open in new window

0
 

Author Closing Comment

by:Murray Brown
ID: 37816717
Great answer.Thanks very much
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

762 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