• GridControl 继承写法修改自己的GridControl


    代码如下:

    View Code
    namespace GridControlDemo
    {
        class MyGridControl : GridControl
        {
            protected override BaseView CreateDefaultView()
            {
                return CreateView("MyGridView");
            }
            protected override void RegisterAvailableViewsCore(InfoCollection collection)
            {
                base.RegisterAvailableViewsCore(collection);
                collection.Add(new MyGridViewInfoRegistrator());
            }
        }
    
        public class MyGridViewInfoRegistrator : GridInfoRegistrator
        {
            public override string ViewName { get { return "MyGridView"; } }
            public override BaseView CreateView(GridControl grid)
            {
                return new MyGridView(grid as GridControl);
            }
        }
    
    
        public class MyGridView : GridView
        {
            /// <summary>
            ///函数
            /// </summary>
            /// <param name="ownerGrid"></param>
            public MyGridView(GridControl ownerGrid) : base(ownerGrid) { }
    
            /// <summary>
            /// 函数
            /// </summary>
            public MyGridView()
            {
    
            }
    
            /// <summary>
            /// 初始化一些默认值
            /// </summary>
            public override void BeginInit()
            {
                base.BeginInit();
                // 设置为多选
                this.OptionsSelection.MultiSelect = true;
                this.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.RowSelect;
                this.FocusedRowHandle = 0;
                this.Focus(); 
                //显示筛选
                this.OptionsView.ShowAutoFilterRow = true;
                //隐藏提示
                this.OptionsView.ShowGroupPanel = false;
                //禁止编辑
                this.OptionsBehavior.Editable = false;
                this.OptionsView.EnableAppearanceEvenRow = false; //是否启用偶数行外观
                this.OptionsView.EnableAppearanceOddRow = false; //是否启用奇数行外观
                this.OptionsView.ShowFilterPanelMode = ShowFilterPanelMode.Never; //是否显示过滤面板
    
                this.OptionsCustomization.AllowColumnMoving = false; //是否允许移动列
                this.OptionsCustomization.AllowColumnResizing = false; //是否允许调整列宽
                this.OptionsCustomization.AllowGroup = false; //是否允许分组
                this.OptionsCustomization.AllowFilter = false; //是否允许过滤
                this.OptionsCustomization.AllowSort = true; //是否允许排序  
            }
    
            public override void EndInit()
            {
                base.EndInit();
                this.SelectionChanged += MyGridView_SelectionChanged;
            }
    
            void MyGridView_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
            {
                int[] grvarry = this.GetSelectedRows();
                if (grvarry.Length > 1)
                {
                   /* for (int i = 0; i < grvarry.Length; i++)
                    {
                        GetDataRowList[i] = this.GetDataRow(grvarry[i]);
                    }*/
                    GetList = grvarry;
    
                }
                else
                {
                    GetDataRowInfo = this.GetFocusedDataRow();
                }
                //GetDataRowInfo = this.GetFocusedDataRow();
            } 
    
            /// <summary>
            /// 获取用户选择行数据
            /// </summary>
            public DataRow GetDataRowInfo { get; set; }
            /// <summary>
            /// 返回选择行数组
            /// </summary>
            public DataRow[] GetDataRowList { get; set; }
            /// <summary>
            /// 返回用户选择行索引
            /// </summary>
            public int[] GetList { get; set; }
        }
    }
  • 相关阅读:
    [LeetCode] 374. Guess Number Higher or Lower
    [LeetCode] 35. Search Insert Position
    [LeetCode] 205. Isomorphic Strings
    [LeetCode] 87. Scramble String
    [LeetCode] 274. H-Index
    [LeetCode] 507. Perfect Number
    [LeetCode] 88. Merge Sorted Array
    [LeetCode] 283. Move Zeroes
    [LeetCode] 287. Find the Duplicate Number
    [LeetCode] 204. Count Primes
  • 原文地址:https://www.cnblogs.com/freexiaoyu/p/2693925.html
Copyright © 2020-2023  润新知