啊鑫
2024-07-11 afbf8700d137710713db61955879d0f5acb73738
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#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
{
    /// <summary>
    ///     表格指示列自动显示行号,表格数据源为空在表格中间显示提醒字符
    /// </summary>
    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();
        }
 
        /// <summary>
        ///     表格指示列自动显示行号,表格数据源为空在表格中间显示提醒字符
        /// </summary>
        /// <param name="gv"></param>
        public static void InitialGridView(GridView gv)
        {
            gv.IndicatorWidth = 35;
            gv.CustomDrawRowIndicator += gv_CustomDrawRowIndicator;
            gv.CustomDrawEmptyForeground += gv_CustomDrawEmptyForeground;
        }
    }
}