We help IT Professionals succeed at work.

programatically retrieving images in resources

r3nder
r3nder asked
on
164 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

Comment
Watch Question

Alexandre SimõesSoftware Architect
CERTIFIED EXPERT

Commented:
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?

Author

Commented:
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
Alexandre SimõesSoftware Architect
CERTIFIED EXPERT

Commented:
What do you have? A resource file with images inside or the images in the project as embedded resource?
Software Architect
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
yes it is embedded in the resources file - I  am on my way to work - so I will try it

Author

Commented:
Worked perfect ....thank  you Alexandre
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.