How can I change column fore color in DataGridview as per condition?
- by Ashish
hi,
i have one table like employee and one of its row is 'status'
if status value is 'approve' then i want to show that row in green color
and else i want to show it in red color.
i have tried following but not working
if (e.Row.RowType == DataControlRowType.Header)
{
string status = DataBinder.Eval(e.Row.DataItem, "IsApprove").ToString();
if (status == "pending")
{
e.Row.ForeColor = System.Drawing.Color.Red; // Change the row's Text color
}
}
ALSO THIS ONE
private void gvleavedetail_cellformatting(object sender, datagridviewcellformattingeventargs e)
{
// if the column is the artist column, check the
// value.
if (this.gvleavedetail.columns[e.columnindex].name == "artist")
{
if (e.value != null)
{
// check for the string "pink" in the cell.
string stringvalue = (string)e.value;
stringvalue = stringvalue.tolower();
if (stringvalue == "high")
{
e.cellstyle.backcolor = color.pink;
}
}
}
But in this case i'm getting error for datagridviewcellformattingeventargs
I'm using VS2010