Reputation: 77
I want to color only certain cells of specified columns(Field1 and Field2) of Rows that respect my conditions. The code bellow colors the right rows, but all the columns(of that rows).
private void gvPriceListManagement_RowCellStyle(object sender, RowCellStyleEventArgs e)
{
if (gvPriceListManagement.GetRowCellValue(e.RowHandle, "Field1") == DBNull.Value)
{
e.Appearance.BackColor = Color.LightCoral;
}
else if (Convert.ToDecimal(gvPriceListManagement.GetRowCellValue(e.RowHandle, "Price")) != Convert.ToDecimal(gvPriceListManagement.GetRowCellValue(e.RowHandle, "Field2")))
{
e.Appearance.BackColor = Color.Yellow;
}
}
How can I color only the specified columns?
Upvotes: 0
Views: 467
Reputation: 640
To colour only specific cells in the grid, add some additional logic to only colour one column of the row:
private void gvPriceListManagement_RowCellStyle(object sender, RowCellStyleEventArgs e)
{
if (e.Column.FieldName = "Field1" &&
vPriceListManagement.GetRowCellValue(e.RowHandle, "Field1") == DBNull.Value)
{
e.Appearance.BackColor = Color.LightCoral;
}
else if (e.Column.FieldName = "Price" &&
Convert.ToDecimal(gvPriceListManagement.GetRowCellValue(e.RowHandle, "Price")) !=
Convert.ToDecimal(gvPriceListManagement.GetRowCellValue(e.RowHandle, "Field2")) &&)
{
e.Appearance.BackColor = Color.Yellow;
}
}
Upvotes: 1