Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 640
  • Last Modified:

VB.net assign image to TreeView node by name

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
Murray Brown
Asked:
Murray Brown
  • 2
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Great answer.Thanks very much
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now