Skip to content

SVG Icon color in DataGridView #1112

Closed
Closed

Description

@itg-assistant

Andi Gordon asked 2017-09-21 11:02:00 UTC

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);
}

Activity

  1. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Frank (ITG) answered 2017-09-21 11:53:22 UTC

    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:

    http://wisej.com/docs/html/Images.htm

    Best regards
    Frank

  2. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Andi Gordon answered 2017-09-21 13:59:00 UTC

    Perfect. That worked :)

    Thank you.

  3. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Luca answered 2017-09-21 15:34:42 UTC

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    GeneralQuestions, how-tos and everything else.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions