zoukankan      html  css  js  c++  java
  • DevGridview中根据条件改变行颜色及单元颜色

     就一功能,没什么别的意思,就是记录着我用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


  • 相关阅读:
    [luogu3334]抛硬币
    [luogu3706]硬币游戏
    [luogu4548]歌唱王国
    [hdu4652]Dice
    [atAGC013F]Two Faced Cards
    [atAGC045F]Division into Multiples
    [atAGC045E]Fragile Balls
    [atAGC045D]Lamps and Buttons
    [luogu5574]任务分配问题
    [luogu4331]数字序列
  • 原文地址:https://www.cnblogs.com/yhongl/p/3937918.html
Copyright © 2011-2022 走看看