Solved

VB.net assign image to TreeView node by name

Posted on 2012-04-06
4
629 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

18 Experts available now in Live!

Get 1:1 Help Now