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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM