我希望通过该代码仅对空白单元格进行着色。
但是我让所有细胞都变色了。
谁能告诉我我的错在哪里..

private void gridView3_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
        GridView View = sender as GridView;
        if(e.Column.FieldName == "First Name")
        {
            string category = View.GetRowCellDisplayText(e.RowHandle, View.Columns["First Name"]);
            if(category != "")
            {
                e.CellStyle.BackColor = Color.DeepSkyBlue;
            }
        }
}

最佳答案

好吧,条件是错误的:

if (category != "")


您正在过滤,以使非空的单元格变为彩色。因此,首先用String.IsNullOrEmpty(category)替换它。

接下来,因为您使用的是DevExpress控件,也许您可​​以使用内置的条件格式设置:http://documentation.devexpress.com/#WindowsForms/CustomDocument759

可能是这样的:

StyleFormatCondition condition1 = new DevExpress.XtraGrid.StyleFormatCondition();
condition1.Appearance.BackColor = Color.DeepSkyBlue;
condition1.Appearance.Options.UseBackColor = true;
condition1.Condition = FormatConditionEnum.Expression;
condition1.Expression = "[First Name] == ''";
gridView1.FormatConditions.Add(condition1);

10-08 09:04