Solved

programatically retrieving images in resources

Posted on 2014-12-09
6
136 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
Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 500 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

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 connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Six Sigma Control Plans

717 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