• Devexpress GridView 数据格式化显示


     gridView1.CustomColumnDisplayText += gridView1_CustomColumnDisplayText;
     void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
            {
                if (e.Column.FieldName == "State")
                {
                    switch (e.DisplayText)
                    {
                        case "0":
                            e.DisplayText = "有效";
                            break;
                        case "1":
                            e.DisplayText = "无效";
           
                            break;
                    }
                }
            }
        void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
            {
                var currentView = sender as GridView;
                if (currentView != null && e.RowHandle == currentView.FocusedRowHandle) return;
                Rectangle r = e.Bounds;
                if (e.Column.FieldName == "F_State")
                {
                    if (e.CellValue.ToString().Equals("False"))
                    {
                        e.Appearance.ForeColor=Color.Red;
                        e.Appearance.DrawString(e.Cache,e.DisplayText,r);
                        e.Handled = true;
                    }
    } }

    或者以下面的这种形式也可以的、


    还有一个就是改变行的颜色
    在对GridControl绑定好数据后:
    No.1:右键GridControl选择Run Designer;
    No.2:Appearance下Style Conditions点击Add,需要注意的是每一个变色条件都得Add一个变色方案;
    No.3:在Properties中需要用到的属性依次往下详解为:
    a)Appearance下BackColor=255.255.128,BackColor2=255.255.128,此项指定符合特定条件时单元格/行背景颜色,如果两项设置颜色不同时则为渐变效果;



    要是每次都这样设置也太不方便了。。所以我又封装了一个方法
            public void SetColumnFormatCell(object value1, object value2,Color backColor1,Color backColor2,GridColumn gridColumn,FormatConditionEnum formatType,GridView gridView)
            {
                var styleFormatCondition1 = new StyleFormatCondition();
                styleFormatCondition1.Appearance.BackColor = backColor1;
                styleFormatCondition1.Appearance.BackColor2 =backColor2;
                styleFormatCondition1.Appearance.Options.UseBackColor = true;
                styleFormatCondition1.Column = gridColumn;
                styleFormatCondition1.Condition = formatType;
                styleFormatCondition1.Expression = "true";
                styleFormatCondition1.Value1 = value1;
                styleFormatCondition1.Value2 = value2;
                gridView.FormatConditions.Add(styleFormatCondition1);
            }
    调用:
      var dev=new DataGridControlHelper();
          dev.SetColumnFormatCell("无效","无效",Color.Red,Color.Red,gridColumn03,FormatConditionEnum.Equal,gridView1);
            


     虽然效果是出来了。但是我觉得效率很差。
    要是有那位网友有更好的方案。请分享一下。谢谢
  • 相关阅读:
    python的thread模块作用
    Python2、3解释器inpurt()函数的区别
    python中的单例设计模式
    Python2、3解释器中字符串中的区别
    浏览器向服务器发送请求的请求头解析
    Python中输出函数print()的三个参数
    Python中四种交换两个变量的值的方法
    学习爬虫看着篇(基础篇)
    Python读写txt文件时的编码问题
    网页和自然语言处理中的字符问题(半角和全角)
  • 原文地址:https://www.cnblogs.com/w2011/p/3573100.html
Copyright © 2020-2023  润新知