Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

programatically retrieving images in resources

Posted on 2014-12-09
6
Medium Priority
?
151 Views
Last Modified: 2014-12-10
I am getting an invalid cast - I was wondering if this is even possible or is there a better way to do this
 private void dgvCurrentUnSerialized_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            for (int i = 0; i < dgvCurrentUnSerialized.Rows.Count; i++)
            {
                DataGridViewImageCell cell = dgvCurrentUnSerialized.Rows[i].Cells[0] as DataGridViewImageCell;
                var value = "(System.Drawing.Image)Properties.Resources._" + Convert.ToString(dgvCurrentUnSerialized.Rows[i].Cells[5].Value) + "_sm";
                cell.Value = value;
 
         }
}

Open in new window

0
Comment
Question by:r3nder
  • 3
  • 3
6 Comments
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 40490654
You're setting the value of the column as a string with the code you should be calling ion the C#...
As far as I understood from the code, the cell has the image name and you want to use it to get the image from an embedded resource?
0
 
LVL 6

Author Comment

by:r3nder
ID: 40491141
yes but how? is the  question. How do I dynamically get an item from the resource table if I want to "build" the name of the resource
0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 40491156
What do you have? A resource file with images inside or the images in the project as embedded resource?
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 2000 total points
ID: 40491173
From your question I guess you have a Resource file right?
So you can do this like:
String nameOfTheImage = "_" + Convert.ToString(dgvCurrentUnSerialized.Rows[i].Cells[5].Value) + "_sm";
Object obj = Resource1.ResourceManager.GetObject(nameOfTheImage);
System.Drawing.Bitmap image = ((System.Drawing.Bitmap)(obj));

cell.value = image;

Open in new window

Resource1 is the name of your resources file (something like Resources1.resx)
0
 
LVL 6

Author Comment

by:r3nder
ID: 40491203
yes it is embedded in the resources file - I  am on my way to work - so I will try it
0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 40491569
Worked perfect ....thank  you Alexandre
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Screencast - Getting to Know the Pipeline

972 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