Dev-Gridview中根据条件改变行颜色及单元颜色

 就一功能,没什么别的意思,就是记录着我用DX的一些困难信息集合:

 

只接上代码,

       //改变行的效果
     private void gridView2_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        {
            DevExpress.Utils.AppearanceDefault appNotPass1 = new DevExpress.Utils.AppearanceDefault(Color.Black, Color.Salmon, Color.Empty, Color.SeaShell, System.Drawing.Drawing2D.LinearGradientMode.Horizontal);
            DevExpress.Utils.AppearanceDefault appNotPass2 = new DevExpress.Utils.AppearanceDefault(Color.Black, Color.Yellow, Color.Empty, Color.SeaShell, System.Drawing.Drawing2D.LinearGradientMode.Horizontal);

            DataRow dr = gridView2.GetDataRow(e.RowHandle);
            if (dr != null)
            {
                if (dr["sex"].ToString() == "女" && dr["birthday1"].ToString().Trim() == "55")
                    DevExpress.Utils.AppearanceHelper.Apply(e.Appearance, appNotPass2);
                else if (dr["sex"].ToString() == "男" && dr["birthday1"].ToString().Trim() == "60")
                    DevExpress.Utils.AppearanceHelper.Apply(e.Appearance, appNotPass1);
            }
        }
//改变单元格的应用
        private void gridView2_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {

            DevExpress.Utils.AppearanceDefault appNotPass1 = new DevExpress.Utils.AppearanceDefault(Color.Black, Color.Salmon, Color.Empty, Color.SeaShell, System.Drawing.Drawing2D.LinearGradientMode.Horizontal);
            DevExpress.Utils.AppearanceDefault appNotPass2 = new DevExpress.Utils.AppearanceDefault(Color.Black, Color.Yellow, Color.Empty, Color.SeaShell, System.Drawing.Drawing2D.LinearGradientMode.Horizontal);
            if (e.Column.FieldName == "sex")
            {
                DataRow dr = gridView2.GetDataRow(e.RowHandle);
                string strTemp = dr[e.Column.FieldName].ToString().Trim();
                if (!string.IsNullOrEmpty(strTemp))
                {
                    switch (strTemp)
                    {
                        case "男":
                            DevExpress.Utils.AppearanceHelper.Apply(e.Appearance, appNotPass1);
                            break;
                        case "女":
                            DevExpress.Utils.AppearanceHelper.Apply(e.Appearance, appNotPass2);
                            break;
                    }
                }

            }

        }

分别激发是这两个事件:

RowStyle
RowCellStyle

处理上有小点变化,根据需求然后变化.


DX 官方也有说明


url

http://documentation.devexpress.com/#WindowsForms/CustomDocument758


posted @ 2011-08-24 15:22  凡海雨  阅读(759)  评论(0编辑  收藏  举报