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
denny

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
}

Hi Mintja
thank you for the explanation
it work

denny

        DataGridViewImageColumn img = new DataGridViewImageColumn();
        Image image = Image.FromFile("Image Path");
        img.Image = image;
        dataGridView1.Columns.Add(img);
        img.HeaderText = "Image";
        img.Name = "img";

full source : Image in datagridview

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.