首页 > 编程 > C# > 正文

DevExpress实现GridView当无数据行时提示消息

2020-01-24 02:34:25
字体:
来源:转载
供稿:网友

本文实例展示了DevExpress实现GridView当无数据行时提示消息的方法,具体步骤如下:

主要功能代码部分如下:

/// <summary>/// 设置当没有数据行的提示信息『CustomDrawEmptyForeground』/// </summary>/// <param name="gridView">GridView</param>/// <param name="e">CustomDrawEventArgs</param>/// <param name="noRecordMsg">提示信息</param>public static void DrawNoRowCountMessage(this GridView gridView, CustomDrawEventArgs e, string noRecordMsg){  if (gridView == null) throw new ArgumentNullException("gridView");  if (gridView.RowCount == 0)  { if (!string.IsNullOrEmpty(noRecordMsg)) {   Font _font = new Font("宋体", 10, FontStyle.Bold);   Rectangle _r = new Rectangle(e.Bounds.Left + 5, e.Bounds.Top + 5, e.Bounds.Width - 5, e.Bounds.Height - 5);   e.Graphics.DrawString(noRecordMsg, _font, Brushes.Black, _r); }  }}

代码使用方法如下:

private void gvLampTotal_CustomDrawEmptyForeground(object sender, DevExpress.XtraGrid.Views.Base.CustomDrawEventArgs e){  gvLampTotal.DrawNoRowCountMessage(e, "暂无符合的数据!");}

代码运行效果如下:

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表