How can I change column fore color in DataGridview as per condition?
Posted
by
Ashish
on Stack Overflow
See other posts from Stack Overflow
or by Ashish
Published on 2010-12-28T13:41:50Z
Indexed on
2010/12/28
13:54 UTC
Read the original article
Hit count: 168
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
© Stack Overflow or respective owner