locked
How to add an image to datagridviewimage column. RRS feed

  • Question

  • Hi.

     

    How to add an image to datagridviewimage column.

     

    Please help me by providing some code snippets

     

    Srdeivi
    Thursday, April 3, 2008 8:50 AM

Answers

  • Ok, so instead resource file use your image list:

     

    Code Snippet

    dataGridView1.Rows.Add("test", "test1", imageList1.Images[0]);

     

    And for conditional basis use 'if' statements.

     

    As for adding columns use designer to add it manually or use code below to add columns programatically.

    Code Snippet

    DataGridViewColumn dgvcol = new DataGridViewColumn(new DataGridViewImageCell());

    dgvcol.HeaderText = "Some column name";

    dataGridView1.Columns.Add(dgvcol);

     

    Friday, April 4, 2008 7:26 AM

All replies

  • Thursday, April 3, 2008 10:32 AM
  • Hi, thanks for thr reply.

    But the given link is having stuff relaetd to DataGrid.

    But i need for Datagridview,(like how to add images to datagridviewimage column

    on conditional basis)

     

    Thursday, April 3, 2008 11:09 AM
  • Hi

    For example you have DataGridView control named 'dataGridView1' with two text columns and one image column. You have also an images in resource file named 'image00' and 'image01'.

     

    You can add images while adding rows like this:

    Code Snippet

    dataGridView1.Rows.Add("test", "test1", Properties.Resources.image00);

     

    You can also change image while your app is running:

    Code Snippet

    dataGridView1.Rows[0].Cells[2].Value = Properties.Resources.image01;

     

    I hope this will help you.
    Thursday, April 3, 2008 12:57 PM
  •  

    Thanks for the reply.

     

    But , i am having the images stored in image list, not in resource file.

    Please give  feasible solution. for how to

    add images to datagridview from imagelist on conditional basis

     

     

    2. I am having another problem toooooo.

       i need to place image columns, and text columns on the datagring as

       unbound columns. Please help me.

    Friday, April 4, 2008 4:14 AM
  • Ok, so instead resource file use your image list:

     

    Code Snippet

    dataGridView1.Rows.Add("test", "test1", imageList1.Images[0]);

     

    And for conditional basis use 'if' statements.

     

    As for adding columns use designer to add it manually or use code below to add columns programatically.

    Code Snippet

    DataGridViewColumn dgvcol = new DataGridViewColumn(new DataGridViewImageCell());

    dgvcol.HeaderText = "Some column name";

    dataGridView1.Columns.Add(dgvcol);

     

    Friday, April 4, 2008 7:26 AM
  •  

    Thanks alot for the solution.

     

    UR code snippets are useful to my requirement.

    Tuesday, April 8, 2008 12:35 PM