Dev中GridView——背景颜色改变

DevExpress.XtraGrid.Views 设置指定行的背景颜色

1.事件:CustomDrawCell
2.示例:
 private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            if (gridView1.GetRow(e.RowHandle) == null)
            {
                return;
            }
            else
            {

    if(e.Column.FieldName=="字段")//是gridView1里面字段的FieldName名字 或者caption名字都行的
               //获取所在行指定列的值
                string state = gridView1.GetRowCellValue(e.RowHandle, "字段").ToString();////是gridView1里面字段的FieldName名字 或者caption名字都行的
              //比较指定列的状态
                if (state == "1") //条件判断
                {
                    e.Appearance.BackColor = Color.NavajoWhite;//设置此行的背景颜色
                }
            }
        }

 

 

DevExpress中XtraGrid控件对GridView每行的颜色设置 zt

改变行颜色

private void GridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        {
            DevExpress.XtraGrid.Views.Grid.GridView view = sender as DevExpress.XtraGrid.Views.Grid.GridView;
            if (e.RowHandle >= 0)
            {
                string category = view.GetRowCellDisplayText(e.RowHandle, view.Columns["dS"]);
                if (category == "")
                {
                    e.Appearance.BackColor = Color.Red;
                    //e.Appearance.BackColor2 = Color.SeaShell;
                }
            }
        }

改单元格颜色

private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
         {
             if (e.Column.FieldName == "cgrbh")
             {
                 string aa = gridView1.GetRowCellDisplayText(e.RowHandle, gridView1.Columns["cgrbh"]);
                 if (aa == "6666")
                 {
                     e.Appearance.BackColor = Color.DeepSkyBlue;
                     e.Appearance.BackColor2 = Color.LightCyan;
                 }
             }

 

posted @ 2019-06-21 17:55  爱笑的小宇宙  阅读(3467)  评论(0编辑  收藏  举报