[DevExpress]GridView扩展-行号_CustomDrawRowIndicator

这篇博客介绍了如何在DevExpress的GridView控件中显示行号,并提供了调用方法DevEx.GridViewEx.SetShowRowNo(gridView1)。内容来源于一篇CSDN上的详细教程。
摘要由CSDN通过智能技术生成
public static class GridViewEx
    {
        public static void SetShowRowNo(this GridView gv)
        {
            Debug.Assert(gv != null);
 
            gv.OptionsView.ShowIndicator = true;
            gv.ResetIndicatorWidth();
 
            //设置行号
            gv.CustomDrawRowIndicator += delegate(object sender, RowIndicatorCustomDrawEventArgs e)
            {
                IndicatorObjectInfoArgs info = e.Info;
                if (info == null || !info.IsRowIndicator || e.RowHandle < 0)
                    return;
                info.Appearance.TextOptions.HAlignment = HorzAlignment.Center;
                info.DisplayText = (e.RowHandle + 1).ToString();
            };
 
            //行数改变
            gv.RowCountChanged += delegate(object sender, EventArgs e)
            {
                GridView selfView = sender as GridView;
                if (selfView == null)
                    return;
                selfView.ResetIndicatorWidth();
            };
 
            //gv有子表时,展开子表重置其行号宽度
            gv.MasterRowExpanded += delegate(object sender, CustomMasterRowEventArgs e)
            {
                GridView View = sender as GridView;
                if (View == null)
                    return;
                GridView dView = View.GetDetailView(e.RowHandle, e.RelationIndex) as GridView;
                if (dView == null)
                    return;
                dView.ResetIndicatorWidth();
            };
 
        }
 
 
 
        /// <summary>
        /// 重置行号宽度
        /// </summary>
        /// <param name="gvw"></param>
        /// <param name="rowCount"></param>
        public static void ResetIndicatorWidth(this GridView gvw, int rowCount = -1)
        {
            Debug.Assert(gvw != null);
 
            gvw.IndicatorWidth = GetIndicatorWidth(rowCount == -1 ? gvw.RowCount : rowCount);
        }
 
        //行号宽度
        private static int GetIndicatorWidth(int p)
        {
            return 7 * p.ToString().Length + 30;
        }
    }

调用:

DevEx.GridViewEx.SetShowRowNo(gridView1);
在这里插入图片描述
转自:https://blog.csdn.net/sgs595595/article/details/52293315

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值