• DevExpress GridView控件设置默认选中的行颜色


    this.gridView1.Appearance.FocusedRow.BackColor = System.Drawing.Color.DarkSalmon;
    this.gridView1.Appearance.FocusedRow.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold);
    this.gridView1.Appearance.FocusedRow.ForeColor = System.Drawing.Color.White;
    this.gridView1.Appearance.FocusedRow.Options.UseBackColor = true;
    this.gridView1.Appearance.FocusedRow.Options.UseFont = true;
    this.gridView1.Appearance.FocusedRow.Options.UseForeColor = true;
    this.gridView1.Appearance.HideSelectionRow.BackColor = System.Drawing.Color.DarkSalmon;
    this.gridView1.Appearance.HideSelectionRow.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold);
    this.gridView1.Appearance.HideSelectionRow.ForeColor = System.Drawing.Color.White;
    this.gridView1.Appearance.HideSelectionRow.Options.UseBackColor = true;
    this.gridView1.Appearance.HideSelectionRow.Options.UseFont = true;
    this.gridView1.Appearance.HideSelectionRow.Options.UseForeColor = true;

    效果:

    DevExpress为.NET平台提供了很多优秀美观的Ui控件,给数据和图表展示带来了极大的便捷性。这里使用的是DevExpress2015版本,安装起来也很方便,只要运行DevExpressUniversalTrialComplete-20151209.exe,一路默认即可。

    当然由于刚开始接触,也遇到一些问题。比如DevExpress GridView控件,是用来展示表格样式的数据,其内嵌到gridControl组件中,只要在它的列属性中“FieilName”属性设置好与数据库关联的字段名称,就可以很好的展示数据库记录了:
    字段关联
    GridView显示数据行背景默认是白色的,为了有时能突出重点,需要设置为其他颜色。参考一些资料,添加RowStyle事件:

    this.gridView1.RowStyle += new DevExpress.XtraGrid.Views.Grid.RowStyleEventHandler(this.gridView1_RowStyle);

    然后在gridView1_RowStyle函数中根据不同的字段名称显示不同颜色:

    private void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
            {
                DataRow dr = gridView1.GetDataRow(e.RowHandle);
                if (dr != null)
                {
                    if (dr["GasType"].ToString() == "LNG")
                    {
                        e.Appearance.BackColor = Color.LightPink;
                    }
                    else
                    {
                        if (dr["GasType"].ToString() == "CNG")
                        {
                            e.Appearance.BackColor = Color.GreenYellow;
                        }
                    }
                }
            }

    显示结果如下:
    不同颜色显示
    但这里有个问题,就是选中行还是灰色的,显然里面的设置对于选中行并没有起作用。还得对其进行其他处理,运行“Run Designer”设置:
    Run Designer设置
    在“Appearance”菜单里设置“FocusedRow”参数和“HideSelectionRow”参数的BackColor为暗红色:
    FocusedRow设置
    HideSelectionRow设置
    之后再运行程序,就发现表中默认选中的行变为了暗红色:
    默认颜色

  • 相关阅读:
    Win10下TensorFlow安装错误解决:Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
    OA Framework or ADF?
    Why do I get the error REP-0713 when I run my report?
    Example Report Using FND FORMAT_CURRENCY
    FND SRWINIT & FND SRWEXIT
    【转】Oralce PL/SQL 堆栈信息追踪
    .net core 杂记:用Autofac替换内置容器
    .net core 杂记:日记记录
    Entity Framework 查漏补缺 (三)
    Entity Framework 查漏补缺 (二)
  • 原文地址:https://www.cnblogs.com/GarsonZhang/p/13968295.html
Copyright © 2020-2023  润新知