Solved

programatically retrieving images in resources

Posted on 2014-12-09
6
124 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# XML Get Values 4 35
Problem to copy file 14 51
.NET - find out if application is running on Windows 2012 server 3 35
ComboBox to String Not Working 5 17
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

733 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