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         }

按照需要請自行修改。

結束!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM