【问题标题】:Change the color of a cell in gridview devexpress not row在gridview devexpress中更改单元格的颜色而不是行
【发布时间】:2016-07-31 08:26:51
【问题描述】:

我有一个grid view devexpress c# 显示大量数据,我需要根据数据值设置单元格的颜色,如您所见:

  private void gridView_RowStyle_1(object sender, RowStyleEventArgs e)
        {
            if (e.RowHandle >= 0)
            {


                // Some condition
                if (gridView.GetRowCellValue(e.RowHandle, gridView.Columns["Id"]).ToString() == "2")
                {
                    e.Appearance.BackColor = Color.Green;
                }
            }
        }

但是这个函数改变的是整行的颜色而不是单元格。如何设置单元格的颜色?

【问题讨论】:

  • 这里的 grid 是 simple 还是 devexpress grid ?

标签: c# gridview devexpress


【解决方案1】:

使用GridView.RowCellStyle事件如下:

    void gridView1_RowCellStyle( object sender, RowCellStyleEventArgs e)
    {
       GridView currentView = sender as GridView;
       if (e.Column.FieldName == "Customer" )
       {
          bool value = Convert.ToBoolean(currentView.GetRowCellValue(e.RowHandle, "Flag_Customer" ));
           if (value)
           e.Appearance.BackColor = Color.Red;
       }
       if (e.Column.FieldName == "Vendor" )
       {
          bool value = Convert.ToBoolean(currentView.GetRowCellValue(e.RowHandle, "Flat_Vendor" ));
          if (value)
          e.Appearance.BackColor = Color.Red;
       }
    }

【讨论】:

    猜你喜欢
    • 2013-08-13
    • 2017-04-19
    • 1970-01-01
    • 1970-01-01
    • 2014-08-24
    • 2013-12-15
    • 2011-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多