Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

programatically retrieving images in resources

Posted on 2014-12-09
6
Medium Priority
?
142 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
[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
  • 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
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

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.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Introduction to Processes

715 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