#region
using System.Data;
using System.Drawing;
using CSFrameworkV5.Core;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
#endregion
namespace CSFrameworkV5.Library.CommonClass
{
///
/// 表格指示列自动显示行号,表格数据源为空在表格中间显示提醒字符
///
public class GridViewAutoIndicator
{
private static void gv_CustomDrawEmptyForeground(object sender,
CustomDrawEventArgs e)
{
var gv = sender as GridView;
var bindingSource = gv.DataSource as DataView;
if (bindingSource != null && bindingSource.Count == 0)
using (var font = new Font("宋体", 16, FontStyle.Bold))
{
var r = new Rectangle(gv.GridControl.Width / 2 - 100,
gv.GridControl.Height / 2, e.Bounds.Right - 5,
e.Bounds.Height - 5);
e.Graphics.DrawString("没有查询到数据!", font, Brushes.Red, r);
}
}
private static void gv_CustomDrawRowIndicator(object sender,
RowIndicatorCustomDrawEventArgs e)
{
if (e.Info.IsRowIndicator && e.RowHandle >= 0)
e.Info.DisplayText = (e.RowHandle + 1).ToStringEx();
}
///
/// 表格指示列自动显示行号,表格数据源为空在表格中间显示提醒字符
///
///
public static void InitialGridView(GridView gv)
{
gv.IndicatorWidth = 35;
gv.CustomDrawRowIndicator += gv_CustomDrawRowIndicator;
gv.CustomDrawEmptyForeground += gv_CustomDrawEmptyForeground;
}
}
}