Dev中GridControl的GridView 基本样式设置
基本样式图:
代码如下:
1 /// <summary> 2 /// gridView样式 3 /// </summary> 4 /// <param name="gdv"></param> 5 public void GridViewConfig(DevExpress.XtraGrid.Views.Grid.GridView gdv) 6 { 7 #region GridView属性设置 8 //行号所在列的宽度 9 gdv.IndicatorWidth = 40; 10 //顶部面板 可用于分组 11 gdv.OptionsView.ShowGroupPanel = false; 12 //显示底部面板 可用于展示统计 13 gdv.OptionsView.ShowFooter = true; 14 //奇数行的效果设置是否可用 15 gdv.OptionsView.EnableAppearanceEvenRow = true; 16 //失去焦点时 是否保留行选中效果 17 gdv.OptionsSelection.EnableAppearanceHideSelection = false; 18 //是否显示焦点单元格样式 19 gdv.OptionsSelection.EnableAppearanceFocusedCell = false; 20 //只读 21 gdv.OptionsBehavior.ReadOnly = true; 22 //不可编辑 若设置不可编辑 会导致表格中增加的按钮的单击事件不可用 23 gdv.OptionsBehavior.Editable = false; 24 //行选中 25 gdv.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus; 26 //边框 27 //gdv.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder; 28 //关闭列右键菜单 29 gdv.OptionsMenu.EnableColumnMenu = false; 30 //列字体对齐方式 31 gdv.Appearance.HeaderPanel.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; 32 //列字体设置 33 gdv.Appearance.HeaderPanel.Font = new System.Drawing.Font("微软雅黑", 14F, FontStyle.Bold, GraphicsUnit.Pixel); 34 //行字体对齐方式 35 gdv.Appearance.Row.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; 36 //奇数行背景色 37 gdv.Appearance.EvenRow.BackColor = Color.FromArgb(228, 243, 255); 38 //焦点行背景色 39 gdv.Appearance.FocusedRow.BackColor = Color.FromArgb(0, 153, 255); 40 //焦点行字体颜色 41 gdv.Appearance.FocusedRow.ForeColor = Color.White; 42 //FooterPanel字体对齐方式 43 gdv.Appearance.FooterPanel.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; 44 //行字体 45 gdv.Appearance.Row.Font = new System.Drawing.Font("微软雅黑", 14F, FontStyle.Regular, GraphicsUnit.Pixel); 46 //导出相关设置 47 gdv.AppearancePrint.Row.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap; 48 gdv.OptionsPrint.AutoWidth = false; 49 gdv.AppearancePrint.Row.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; 50 #endregion 51 52 #region 行号显示 53 gdv.CustomDrawRowIndicator += (s, e) => 54 { 55 e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far; 56 e.Appearance.Font = new System.Drawing.Font("微软雅黑", 14F, FontStyle.Regular, GraphicsUnit.Pixel); 57 if (e.Info.IsRowIndicator && e.RowHandle >= 0) 58 { 59 60 e.Info.DisplayText = Convert.ToString(e.RowHandle + 1); 61 } 62 }; 63 #endregion 64 65 #region 当表格内容为空时显示 66 gdv.CustomDrawEmptyForeground += (s, e) => 67 { 68 if (gdv.RowCount == 0) 69 { 70 string str = "没有查询到数据!"; 71 Font font = new Font("微软雅黑", 14F, FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel); 72 Rectangle rectangle = new Rectangle(e.Bounds.Left + 5, e.Bounds.Top + 5, e.Bounds.Width - 5, e.Bounds.Height - 5); 73 e.Graphics.DrawString(str, font, Brushes.Black, rectangle); 74 } 75 }; 76 77 #endregion 78 }
按照需要请自行修改。
结束!