hello all
I wonder how to fill datagridviewimagecolumn with an icon.
I mean if I place cursor in rows[2],Cells[3] and then i press right mouse down,then certain icon placed in that cells
if I place cursor in rows[4],cells[3] and then press left mouse down,then another certain icon placed in that cells
I have set column [3] as ImageColumn.

Anyone can teach me how ,or just point me to snippet example ?

thank you

5 Years
Discussion Span
Last Post by brianmanee

Create column in a constructor of form (or on load event):

DataGridViewImageColumn imageColumn = new DataGridViewImageColumn();
    imageColumn.Name = "colImages";
    imageColumn.HeaderText = "Images";
    imageColumn.Width = 100;
    imageColumn.ImageLayout = DataGridViewImageCellLayout.Stretch;
    imageColumn.CellTemplate = new DataGridViewImageCell(false);
    imageColumn.DefaultCellStyle.NullValue = null;
datagridview1.Columns.Insert(imageColumn, 1); //1 is an index of column - 2nd column

then try using this kind of code:

Bitmap img = new Bitmap(@"C:\MyFolder\myPicture.jpg");
datagrdiview1[1, 0].Value = img; //0,0 is 1st row, 2nd column
//you can do a loop or something, its up to you

and you can add (subscribe to) an event, so it will show default images, if non inserted yet:

void dataGridView1_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
     e.Row.Cells[1].Value = Properties.Resources.MyDefaultPicure. // add this image to Resources if you want to show it
        DataGridViewImageColumn img = new DataGridViewImageColumn();
        Image image = Image.FromFile("Image Path");
        img.Image = image;
        img.HeaderText = "Image";
        img.Name = "img";

full source : Image in datagridview

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.