Windows Develop Bookmark and Share   
 index > Windows Forms General > DataGridViewImageColumn does not show selected Image
 

DataGridViewImageColumn does not show selected Image

Hello,

I am tryinf to add an image to a DataGridView.
In the DGV I have defined a column that is of DataGridViewImageColumn type.

I have a resource file (Resources.resex) to which I have "imported" my existing image.
When opening the resource file I can see the image displayed correctly.

I have edited the DGV columns and inthe Image column assigned
Image to : MyProject.Properties.Resources.Image.jpg
After that the filed in the properties showed the correct image.

But when I close the "Edit Columns" and go back to the DGV, the only image displayed in that column is a red X (the default picture).

I have been playing with this a few hours nowwithout succes. I have even copied an image that works in another project and added to my resource file, copied theDGV that uses it and try to see if I can make them work in my project as well but that did not work either.

Anyone knows why?

Thanks in advance,
Keren
Keren S  Monday, September 28, 2009 1:39 PM

Hi,

 

The Image property specifies an image that is displayed in cells with no values when the column is not data-bound and the cell's ValueIsIcon property is set to false. (From DataGridViewImageColumn.Image MSDN document)

This means if you drag a datagridview to the form, add a imagecolumn to the datagridviewcontrol, and then add the following code in the form_load event, you will see the image.

 

dataGridView1.Rows.Add(6);

 

By the way, seems you want to set the default value to the iamgecolumn. You can set the value in DataGridView_DefaultValueNeeded event.

        void dataGridView1_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)

        {

            e.Row.Cells[“image”].Value = Test1004.Properties.Resources.smile;

        }

 

More information:

DataGridViewImageColumn.Image Property

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewimagecolumn.image.aspx

 

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Sunday, October 04, 2009 7:00 AM

Hi,

 

The Image property specifies an image that is displayed in cells with no values when the column is not data-bound and the cell's ValueIsIcon property is set to false. (From DataGridViewImageColumn.Image MSDN document)

This means if you drag a datagridview to the form, add a imagecolumn to the datagridviewcontrol, and then add the following code in the form_load event, you will see the image.

 

dataGridView1.Rows.Add(6);

 

By the way, seems you want to set the default value to the iamgecolumn. You can set the value in DataGridView_DefaultValueNeeded event.

        void dataGridView1_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)

        {

            e.Row.Cells[“image”].Value = Test1004.Properties.Resources.smile;

        }

 

More information:

DataGridViewImageColumn.Image Property

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewimagecolumn.image.aspx

 

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Sunday, October 04, 2009 7:00 AM
Strange! I see now that you have replied already two days ago, but I did not receive any alert about it until today when you marked it as answered (only got an alert about it being marked as answered), althought I did have an alarm on it.
I will test your answer immidiately, thanks for replying.
Keren S  Tuesday, October 06, 2009 6:29 AM
Thank you so much for your help. Indeed this fixed everything! :-)
I don't understand though what is the purpose of choosing an Image in the "Edit Columns" dialog if it has no effect?

Thanks again,
Keren
Keren S  Tuesday, October 06, 2009 6:51 AM

The Image property specifies an image that is displayed in cells with no values when the column is not data-bound and the cell's ValueIsIcon property is set to false. (From DataGridViewImageColumn.Image MSDN document)
DataGridViewImageColumn.Image Property
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewimagecolumn.image.aspx

This means if you drag a datagridview to the form, add a imagecolumn to the datagridviewcontrol, and then add the following code in the form_load event, you will see the image.
 
dataGridView1.Rows.Add(6);


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Wednesday, October 07, 2009 2:51 AM

You can use google to search for other answers

Custom Search

More Threads

• DateTimePicker value changes on DropDown if Today is not between DateMin and DateMax
• How to call a B function/method of a MDI parent (Form1)?
• How To Extract Icons From Exe Or Dll Files Using ExtractAssociatedIcon ??
• move focus to next control,whaterver that control is--> at Form's level
• UIP Application Block Version 1.0 upgrade to 2.0
• Outlook calendar - made useful???
• Changing transparent color on BMP
• Windows Server Update Services (WSUS) direct link needed please
• ComboBox Questions!!! [Urgent!!!]
• Saving...update... quering >>> code idea!!!