您当前的位置: 首页 > 

[DevExpress]GridView扩展-行号_CustomDrawRowIndicator

发布时间:2019-07-10 08:47:26 ,浏览量:0

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();
            };
 
        }
 
 
 
        ////// 重置行号宽度
        /////////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

关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    108697博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0466s