DevExpress的GridView设置特定行的样式

GridView控件绑定事件:

            gridView_SampleData.CustomDrawCell += gridView_SampleData_CustomDrawCell;

根据自定义逻辑来改变行属性,例子是判断某个单元格的Is duplicated列是否为yes,若是,则将行标记为黄色。

        //自定义画某行
        private void gridView_SampleData_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            if (gridView_SampleData.GetRow(e.RowHandle) == null)
                return;
            else
            {
                //隐藏标记行
                if (gridView_SampleData.Columns["Is duplicated"] != null)
                {
                    gridView_SampleData.Columns["Is duplicated"].VisibleIndex = -1;
                    //获取所在行指定列的值
                    string duplicated = gridView_SampleData.GetRowCellValue(e.RowHandle, "Is duplicated").ToString();
                    //设置此行的背景颜色
                    if (duplicated == "yes")
                        e.Appearance.BackColor = Color.Yellow;
                }
            }
        }
原文地址:https://www.cnblogs.com/vaecole/p/5882447.html