DatagridView - Image cell

0
0

I need do a logic, and change the image icon in the cell. I am trying reference a image in the cell after construct my datagridview.

What i should do to work?

 

foreach (DataGridViewColumn coluna in MsgDataGridView.Columns)
{
foreach (DataGridViewRow linha in MsgDataGridView.Rows)
{
foreach(DataGridViewCell cell in linha.Cells)
{

if (cell.RowIndex == 1 && aux == 1)
{

MsgColunaIco.CellImage = iconMsgFechada.ToBitmap(); ????????????

MsgDataGridView.Rows.Add(iconMsgFechada.ToBitmap()); ????????????

}
else
{
MsgColunaIco.CellImage = iconMsgAberta.ToBitmap();  ????????????

}
}
}
}

 

  • You must to post comments
0
0

I tried the same sample provided and it works without any issue. You cannot expect to use an Image as a string that is the name of an image file. Also base64 is not the name of an image. If you want to use a bitmap you need to assign it to a property of type Image not string. Try BackgroundImage.

  • You must to post comments
0
0

So… i tried this, but the compiler says to me: you can convert the bitmap to string. This appears that the cellStyle dont receive the image tipe, how i can do, i tried convert in base64 to .. but nothing happens.

method cellformating{

Icon iconMsgFechada = new Icon(serviceMsg.EntregaDiretorio(1) + “MsgFechada.ico”);
Icon iconMsgAberta = new Icon(serviceMsg.EntregaDiretorio(1) + “MsgAberta.ico”);

if (e.ColumnIndex == 1)
{
if (e.Value.Equals(0))
{
e.CellStyle.BackgroundImageSource = iconMsgFechada.ToBitmap();
}
else
{
e.CellStyle.BackgroundImageSource = iconMsgAberta.ToBitmap();
}
}

}

  • You must to post comments
0
0

Hi Jay,

It’s better to use the CellFormatting Event to apply your logic.

I have attached a sample for you!

I would also like to point out that it’s highly recommended that you don’t use the Bitmap() object but instead use the “ImageSource” property and deploy your /Images resources, This way there is no memory usage on the server to load the image and it’s also cached on the browser.

You can check out our DemoBrowser application for more details about this, and I would like to also point you out to another similar post in this forum for more info!

Merry Christmas,
Alaa

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.