c# - How do you add an image to a single specific cell in a DataGridView? -


using c# , visual studio, have datagridview 2 columns. every row, first column display text. every row except 1 specific row, second column display text. in 1 specific cell in second column, need show image.

for example:

row[0].cell[0] = "test"  row [0].cell[1] = "test" row[1].cell[0] = "test"  row [1].cell[1] = "test" row[2].cell[0] = "test"  row [2].cell[1] = need display image here row[3].cell[0] = "test"  row [3].cell[1] = "test" 

there more 1 way here simple example set 1 single cell show image:

    bitmap bmp = (bitmap) bitmap.fromfile(someimagefile);      datagridviewimagecell icell = new datagridviewimagecell();     icell.value = bmp;     datagridview1[1, 2] = icell; 

of course other image source work well..

try not leak bitmaps if change them..


Comments