Link to home
Start Free TrialLog in
Avatar of r3nder
r3nderFlag 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

Avatar of Alexandre Simões
Alexandre Simões
Flag of Switzerland image

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?
Avatar of 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
What do you have? A resource file with images inside or the images in the project as embedded resource?
ASKER CERTIFIED SOLUTION
Avatar of Alexandre Simões
Alexandre Simões
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of r3nder

ASKER

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

ASKER

Worked perfect ....thank  you Alexandre