Solved

VB.net assign image to TreeView node by name

Posted on 2012-04-06
4
628 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:murbro
  • 2
  • 2
4 Comments
 
LVL 85

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:murbro
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 85

Accepted Solution

by:
Mike Tomlinson earned 500 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:murbro
ID: 37816717
Great answer.Thanks very much
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
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 video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

17 Experts available now in Live!

Get 1:1 Help Now