为devexpress中的某些单元格着色

Color certain cells in devexpress

我只想为符合我的条件的行的指定列(Field1 和 Field2)的某些单元格着色。下面的代码为正确的行着色,但所有列(该行的)。

 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;
              }
         }

如何只给指定的列着色?

要仅为网格中的特定单元格着色,请添加一些额外的逻辑以仅为行中的一列着色:

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;
    }
}