[DevExpress]GridView擴展-行號_CustomDrawRowIndicator

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章