基本样式图:
代码如下:
/// <summary>
/// gridView样式
/// </summary>
/// <param name="gdv"></param>
public void GridViewConfig(DevExpress.XtraGrid.Views.Grid.GridView gdv)
{
#region GridView属性设置
//行号所在列的宽度
gdv.IndicatorWidth = ;
//顶部面板 可用于分组
gdv.OptionsView.ShowGroupPanel = false;
//显示底部面板 可用于展示统计
gdv.OptionsView.ShowFooter = true;
//奇数行的效果设置是否可用
gdv.OptionsView.EnableAppearanceEvenRow = true;
//失去焦点时 是否保留行选中效果
gdv.OptionsSelection.EnableAppearanceHideSelection = false;
//是否显示焦点单元格样式
gdv.OptionsSelection.EnableAppearanceFocusedCell = false;
//只读
gdv.OptionsBehavior.ReadOnly = true;
//不可编辑 若设置不可编辑 会导致表格中增加的按钮的单击事件不可用
gdv.OptionsBehavior.Editable = false;
//行选中
gdv.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus;
//边框
//gdv.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
//关闭列右键菜单
gdv.OptionsMenu.EnableColumnMenu = false;
//列字体对齐方式
gdv.Appearance.HeaderPanel.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
//列字体设置
gdv.Appearance.HeaderPanel.Font = new System.Drawing.Font("微软雅黑", 14F, FontStyle.Bold, GraphicsUnit.Pixel);
//行字体对齐方式
gdv.Appearance.Row.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
//奇数行背景色
gdv.Appearance.EvenRow.BackColor = Color.FromArgb(, , );
//焦点行背景色
gdv.Appearance.FocusedRow.BackColor = Color.FromArgb(, , );
//焦点行字体颜色
gdv.Appearance.FocusedRow.ForeColor = Color.White;
//FooterPanel字体对齐方式
gdv.Appearance.FooterPanel.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
//行字体
gdv.Appearance.Row.Font = new System.Drawing.Font("微软雅黑", 14F, FontStyle.Regular, GraphicsUnit.Pixel);
//导出相关设置
gdv.AppearancePrint.Row.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap;
gdv.OptionsPrint.AutoWidth = false;
gdv.AppearancePrint.Row.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
#endregion #region 行号显示
gdv.CustomDrawRowIndicator += (s, e) =>
{
e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
e.Appearance.Font = new System.Drawing.Font("微软雅黑", 14F, FontStyle.Regular, GraphicsUnit.Pixel);
if (e.Info.IsRowIndicator && e.RowHandle >= )
{ e.Info.DisplayText = Convert.ToString(e.RowHandle + );
}
};
#endregion #region 当表格内容为空时显示
gdv.CustomDrawEmptyForeground += (s, e) =>
{
if (gdv.RowCount == )
{
string str = "没有查询到数据!";
Font font = new Font("微软雅黑", 14F, FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
Rectangle rectangle = new Rectangle(e.Bounds.Left + , e.Bounds.Top + , e.Bounds.Width - , e.Bounds.Height - );
e.Graphics.DrawString(str, font, Brushes.Black, rectangle);
}
}; #endregion
}
按照需要请自行修改。
结束!