Gridview 自定义外观

private void Form1_Load(object sender, EventArgs e)
        {
            //汉化,需要引用DevExpress.Localization.v11.2.dll
            DevExpress.XtraEditors.Controls.Localizer.Active = new DevExpress.LocalizationCHS.DevExpressXtraEditorsLocalizationCHS();
            DevExpress.XtraGrid.Localization.GridLocalizer.Active = new DevExpress.LocalizationCHS.DevExpressXtraGridLocalizationCHS();


            #region LoadData
            DataTable tb2 = SQLcreate();
            gridControl1.DataSource = tb2;
            #endregion
            gridViewDev.setDgv(gridView1);


        }

         public DataTable SQLcreate()
        {
            string cmdtxt = "SELECT * FROM v_PersonEx";
            SqlConnection cn = new SqlConnection("server=.;database=SMS;Uid=sa;Pwd=");
            SqlDataAdapter dap = new SqlDataAdapter(cmdtxt, cn);
            DataSet ds = new DataSet();
            dap.Fill(ds, "table");
            return ds.Tables[0];
           
        }
       public void setDgv(DevExpress.XtraGrid.Views.Grid.GridView gridView1) 
        {
            gridView1.OptionsView.ShowColumnHeaders = true;       //显示列标题
            gridView1.OptionsView.ShowIndicator = false;          // 不显示行标题
            gridView1.OptionsView.ShowGroupPanel = true;          // 显示分组panel
            gridView1.OptionsCustomization.AllowGroup = true;     //是否允许分组
            gridView1.OptionsView.ShowGroupedColumns = true;     //显示分组的列
            gridView1.OptionsView.ShowFilterPanelMode = DevExpress.XtraGrid.Views.Base.ShowFilterPanelMode.Never;   //是否显示过滤面板
            gridView1.OptionsCustomization.AllowFilter = true;                      //是否允许过滤


            gridView1.OptionsCustomization.AllowColumnMoving = true;                //是否允许移动列
            gridView1.OptionsCustomization.AllowColumnResizing = false;              //是否允许调整列宽


            gridView1.OptionsCustomization.AllowSort = true;                          //是否允许排序


            gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;           //是否允许选中单元格
            //允许选中行,不允许编辑
            gridView1.OptionsBehavior.EditorShowMode = DevExpress.Utils.EditorShowMode.Click;
            gridView1.OptionsBehavior.Editable = false;                               //是否允许用户编辑单元格


            gridView1.OptionsView.EnableAppearanceEvenRow = true;                    //是否启用偶数行外观
            gridView1.OptionsView.EnableAppearanceOddRow = true;                     //是否启用奇数行外观
            gridView1.OptionsMenu.EnableColumnMenu = false;                          //禁用列标题右键菜单


            // gridView1.ClearSorting();//禁止排序


            gridView1.PaintStyleName = "Flat";   //设置外观样式
            DevExpress.XtraGrid.Views.Grid.GridViewAppearances Appearance1 = new DevExpress.XtraGrid.Views.Grid.GridViewAppearances(gridView1);




            //列标题颜色:System.Drawing.Color.FromArgb(((int)(((byte)(198)))), ((int)(((byte)(232)))), ((int)(((byte)(243))))); 


            //奇数行
            Appearance1.EvenRow.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(236)))), ((int)(((byte)(249)))), ((int)(((byte)(254)))));
            Appearance1.EvenRow.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));


            //偶数行
            Appearance1.OddRow.BackColor = System.Drawing.Color.White;
            Appearance1.OddRow.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));


            //选中行
            Appearance1.FocusedRow.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(254)))), ((int)(((byte)(211)))), ((int)(((byte)(128)))));
            Appearance1.FocusedRow.ForeColor = System.Drawing.Color.Black;


            //分组panel颜色
            Appearance1.GroupPanel.BackColor = System.Drawing.Color.White;
            Appearance1.GroupPanel.BackColor2 = System.Drawing.Color.CornflowerBlue;
            //分组row颜色
            Appearance1.GroupRow.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(198)))), ((int)(((byte)(232)))), ((int)(((byte)(243))))); 
            Appearance1.GroupRow.BackColor2 = System.Drawing.Color.FromArgb(((int)(((byte)(198)))), ((int)(((byte)(232)))), ((int)(((byte)(243)))));
            //空白区域颜色
            Appearance1.Empty.BackColor = System.Drawing.Color.LightYellow;
            //列标题颜色
            Appearance1.HeaderPanel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(210)))), ((int)(((byte)(229)))), ((int)(((byte)(249)))));


    


            //奇数行
            gridView1.Appearance.EvenRow.BackColor = Appearance1.EvenRow.BackColor;
            gridView1.Appearance.EvenRow.Font = Appearance1.EvenRow.Font;
            //偶数行
            gridView1.Appearance.OddRow.BackColor = Appearance1.OddRow.BackColor;
            gridView1.Appearance.OddRow.Font = Appearance1.OddRow.Font;
            //选中行
            gridView1.Appearance.FocusedRow.BackColor = Appearance1.FocusedRow.BackColor;   //选中的行
            gridView1.Appearance.FocusedCell.BackColor = Appearance1.FocusedRow.BackColor;  //选中的单元格
            gridView1.Appearance.FocusedRow.ForeColor = Appearance1.FocusedRow.ForeColor;   //字体颜色
            //分组panel颜色
            gridView1.Appearance.GroupPanel.BackColor = Appearance1.GroupPanel.BackColor;
            gridView1.Appearance.GroupPanel.BackColor2 = Appearance1.GroupPanel.BackColor2;
            //分组row颜色
            gridView1.Appearance.GroupRow.BackColor = Appearance1.GroupRow.BackColor;
            //  gridView1.Appearance.GroupRow.BackColor2 = Appearance1.GroupRow.BackColor2;
            //空白区域颜色
            gridView1.Appearance.Empty.BackColor = Appearance1.Empty.BackColor;
            //列标题颜色
            gridView1.Appearance.HeaderPanel.BackColor = Appearance1.HeaderPanel.BackColor;
            //设置分组
            gridView1.GroupSummary.Add(DevExpress.Data.SummaryItemType.Count, "分组1");  //添加分组1,如果不是count,则名称必须与字段名对应
            gridView1.GroupFormat = "{1} {2}";  //默认"{0}: [#image]{1} {2}"; 字段名称:数据 计数=?
            gridView1.Columns["部门名称"].GroupIndex = 0;  //设置默认分组列
        }
        public void RestoreLayoutFromXml(DevExpress.XtraGrid.Views.Grid.GridView gridView1, string filePath)
        {
            gridView1.Appearance.RestoreLayoutFromXml(filePath);    //加载样式
        }


        public void SaveLayoutToXml(DevExpress.XtraGrid.Views.Grid.GridView gridView1, string filePath)
        {
            gridView1.Appearance.SaveLayoutToXml(filePath);  //保存样式
        }

转载于:https://www.cnblogs.com/benhua/p/4838844.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值