Hi,
So I’m aware that an SVG icon will typically replace the #000000 colour with a control’s ForeColor in Wisej, for example in a button.
I’m trying to acheive the same thing in a DataGridView with little success.
I’m setting the cell Value to the image source and then setting the cell style to have a ForeColor, but the icon does not change.
Is this a supported behaviour in the DataGridView ?
If so what am I missing ?
my code:
private void UpdateCell(DataGridView sender, DataGridViewCachedCellValueEventArgs e)
{
dgComputers.Rows[e.RowIndex].Cells[e.ColumnIndex].Style = new DataGridViewCellStyle() { ForeColor = Color.Red };
e.Value = “icon-new”;
}
private void DgComputers_CellValueNeeded(object sender, DataGridViewCachedCellValueEventArgs e)
{
DataGridView dgv = sender as DataGridView;
UpdateCell(dgv, e);
}
Hello Andi,
To add to Frank’s tip to use ?color (see also https://docs.wisej.com/docs/controls/general/icons).
I have tried the same code you posted and it works fine for me, the color changed to red. What build of Wisej are you using? There was a bug about this few builds ago.
Also, when processing CellValueNeeded the caching of the values is up to the code (you). In Virtual mode the datagrid doesn’t store the value of the cells anywhere. So CellValueNeeded is fired every time the grid needs the value of the cell, which can be hundreds or thousands of times. If you create a new style object every time you end up creating a lot of instances that the GC will have to collect at some point.
HTH
Perfect. That worked 🙂
Thank you.
Hi Andi,
you can simply add the color name after the imagesource, e.g.
e.Value = “icon-new?color=red”;
See our documentation for more details and samples:
https://wisej.com/docs/html/Images.htm
Best regards
Frank
Please login first to submit.