表格指示列自动显示行号,表格数据源为空在表格中间显示提醒字符
作者:C/S框架网  发布日期:2015-01-04 22:03:38
  表格指示列自动显示行号,表格数据源为空在表格中间显示提醒字符





贴图图片



贴图图片




C# Code:

//表格指示列自动显示行号,表格数据源为空在表格中间显示提醒字符
GridViewAutoIndicator.InitialGridView(gvStuct);

//来源:C/S框架网(www.csframework.com) QQ:1980854898






C# Code:

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

//来源:C/S框架网(www.csframework.com) QQ:1980854898


上一篇 下一篇