Search code examples
c#colorscasting

Convert int to Color in Windows Forms


I have a value in row that equals -16777056, but how do I cast it to Color?

Something like that:

Color = (Color) Convert.ToInt32(((DataRowView)this.dataGridView1.Rows[e.RowIndex].DataBoundItem)["Color"]) })

Solution

  • Try this instead:

    var argb = Convert.ToInt32(
        ((DataRowView)this.dataGridView1.Rows[e.RowIndex].DataBoundItem)["Color"]);
    Color = Color.FromArgb(argb);