2

I am trying to add an image in a DataGridView using the following code

DataGridViewImageColumn Editlink = new DataGridViewImageColumn();
Image image = Image.FromFile("Images\\Edit.png");
Editlink.Image = image;
Editlink.HeaderText = "Edit";
Editlink.DataPropertyName = "lnkColumn";
Editlink.Width = 40;

In the above code

Image image = Image.FromFile("Images\\Edit.png");

It throws an error saying

File not found

When I changed the FromFile path to "C:\\Test\\Images\\Edit.png", it works.

How can I achieve the same result without using actual path?

Lews Therin
  • 3,707
  • 2
  • 27
  • 53
Parag Pathari
  • 281
  • 2
  • 5
  • 19
  • The path is relative to the working directory of your application. – stuartd May 24 '16 at 13:44
  • It seems this is what you are looking for: [Adding clickable image/button to datagridview in c#](http://stackoverflow.com/questions/36253732/adding-clickable-image-button-to-datagridview-in-c-sharp) – Reza Aghaei May 24 '16 at 19:23

1 Answers1

0

Please use Add Resource to add Images to local Resource folder and then call it by file name.

The question is a duplicate of this filenotfound-when-i-use-image-fromfile

Community
  • 1
  • 1
Dickson Xavier
  • 99
  • 1
  • 1
  • 11