Avatar of r3nder
r3nder
Flag for United States of America asked on

programatically retrieving images in resources

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

C#.NET ProgrammingProgramming

Avatar of undefined
Last Comment
r3nder

8/22/2022 - Mon
Alexandre Simões

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?
r3nder

ASKER
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ões

What do you have? A resource file with images inside or the images in the project as embedded resource?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
Alexandre Simões

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
r3nder

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

ASKER
Worked perfect ....thank  you Alexandre