LenTompkins
asked on
C# changing backcolor on a cell in a datagridview
I am trying to change the color of a cell in a DataGridView based on the value of the column. I have tried the following attempts:
string value = this.dgvMainBottomRow1["co lCostedBy" , 0].Value.ToString();
switch (value)
{
case "No Ticket Assigned":
this.dgvMainBottomRow1["co lCostedBy" , 0].Style.BackColor = Color.Red;
break;
default:
this.dgvMainBottomRow1["co lCostedBy" , 0].Style.BackColor = Color.White;
break;
}
I also tried:
private void dgvMainBottomRow1_CellForm atting(obj ect sender, DataGridViewCellFormatting EventArgs e)
{
// Check if this is the right column.
if (e.ColumnIndex == 0)
{
string value = e.Value.ToString();
switch (value)
{
case "No Ticket Assigned":
e.CellStyle.BackColor = Color.Red;
break;
default:
e.CellStyle.BackColor = Color.White;
break;
}
}
When I step thru the code, it is setting the back color properly, but when I view the form, it is still not changed.
Is there a grid setting that needs to be changed?
string value = this.dgvMainBottomRow1["co
switch (value)
{
case "No Ticket Assigned":
this.dgvMainBottomRow1["co
break;
default:
this.dgvMainBottomRow1["co
break;
}
I also tried:
private void dgvMainBottomRow1_CellForm
{
// Check if this is the right column.
if (e.ColumnIndex == 0)
{
string value = e.Value.ToString();
switch (value)
{
case "No Ticket Assigned":
e.CellStyle.BackColor = Color.Red;
break;
default:
e.CellStyle.BackColor = Color.White;
break;
}
}
When I step thru the code, it is setting the back color properly, but when I view the form, it is still not changed.
Is there a grid setting that needs to be changed?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER