Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

DataGridViewImageColumn - dynamically set images per grid row

$
0
0
Hi -

I've got a DataGridView with an unbound DataGridViewImageColumn (I'm using VS 2005 beta 2/C#).  Based on a stored db value, I want to display 1 of 4 images in the image column.  I found the following example (or a variation of it) in the online help:

dataGridView.Rows[row.Index].Cells[0].Value = image;
(the index of my ImageColumn is 0)

At runtime, broken images are displayed in the grid column. 

I've also tried to set the image property of the DataGridViewImageColumn using the following code:

DataGridViewImageColumn cell = (DataGridViewImageColumn)dataGridView.Columns[0];
cell.Image = image;

When using this code, I do see images at runtime, but since the property is not row specific, the same image is displayed for all rows and I need the image to vary per row.

When using the cell.Value property do I need to format the image before assigning it?  I found an image formatting example online, but it was in C++ so I didn't completely understand the code. 

There's also the cell.ValueType property, does that need to be set in conjunction with the cell.Value property?

Any help or suggestions would be great!

Thanks
-christine

Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>