程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> DevExpress,GridControl如何添加自定義列,重寫RepositoryItem

DevExpress,GridControl如何添加自定義列,重寫RepositoryItem

編輯:C#入門知識

DevExpress,GridControl如何添加自定義列,重寫RepositoryItem

如何向XtraGrid添加自定義控件

怎樣向XtraGrid中添加自己創建的XtraEditors編輯控件

可以創建 RepositoryItem派生類,並且為其聲明靜態構造方法和注冊方法,如果要在設計器中使用還得給注冊方法添加UserRepositoryItemAttribute屬性標記,還必須重寫RepositoryItem和BaseEdit派生類的EditorTypeName屬性

此用法適用XtraGrid, XtraTreeList, XtraVerticalGrid, XtraBars

注意要添加引用:DevExpress.XtraEditors.v10.2

[C#例子]


[csharp]
using DevExpress.XtraEditors; 
using DevExpress.XtraEditors.Repository; 
using DevExpress.XtraEditors.Registrator; 
using System.Windows.Forms; 
using System.Drawing; 
using System.ComponentModel; 
 
namespace CustomEditors 

    [UserRepositoryItem("Register")] 
    public class RepositoryItemMyEdit : RepositoryItemTextEdit 
    { 
        static RepositoryItemMyEdit() 
        { 
            Register(); 
        } 
        public RepositoryItemMyEdit() { } 
 
        internal const string EditorName = "MyEdit"; 
 
        public static void Register() 
        { 
            EditorRegistrationInfo.Default.Editors.Add(new EditorClassInfo(EditorName, typeof(MyEdit), 
                typeof(RepositoryItemMyEdit), typeof(DevExpress.XtraEditors.ViewInfo.TextEditViewInfo), 
                new DevExpress.XtraEditors.Drawing.TextEditPainter(), true, null, typeof(DevExpress.Accessibility.TextEditAccessible))); 
        } 
        public override string EditorTypeName 
        { 
            get { return EditorName; } 
        } 
    } 
 
    public class MyEdit : TextEdit 
    { 
        static MyEdit() 
        { 
            RepositoryItemMyEdit.Register(); 
        } 
        public MyEdit() { } 
 
        public string DisplayText { set; get; } 
 
        public override string EditorTypeName 
        { 
            get { return RepositoryItemMyEdit.EditorName; } 
        } 
 
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] 
        public new RepositoryItemMyEdit Properties 
        { 
            get { return base.Properties as RepositoryItemMyEdit; } 
        } 
 
        //protected override void OnClickButton(DevExpress.XtraEditors.Drawing.EditorButtonObjectInfoArgs buttonInfo)  
        //{  
        //    ShowPopupForm();  
        //    base.OnClickButton(buttonInfo);  
        //}  
        //protected virtual void ShowPopupForm()  
        //{  
        //    using (Form form = new Form())  
        //    {  
        //        form.StartPosition = FormStartPosition.Manual;  
        //        form.Location = this.PointToScreen(new Point(0, Height));  
        //        form.ShowDialog();  
        //    }  
        //}  
    } 

using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors.Registrator;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;

namespace CustomEditors
{
    [UserRepositoryItem("Register")]
    public class RepositoryItemMyEdit : RepositoryItemTextEdit
    {
        static RepositoryItemMyEdit()
        {
            Register();
        }
        public RepositoryItemMyEdit() { }

        internal const string EditorName = "MyEdit";

        public static void Register()
        {
            EditorRegistrationInfo.Default.Editors.Add(new EditorClassInfo(EditorName, typeof(MyEdit),
                typeof(RepositoryItemMyEdit), typeof(DevExpress.XtraEditors.ViewInfo.TextEditViewInfo),
                new DevExpress.XtraEditors.Drawing.TextEditPainter(), true, null, typeof(DevExpress.Accessibility.TextEditAccessible)));
        }
        public override string EditorTypeName
        {
            get { return EditorName; }
        }
    }

    public class MyEdit : TextEdit
    {
        static MyEdit()
        {
            RepositoryItemMyEdit.Register();
        }
        public MyEdit() { }

        public string DisplayText { set; get; }

        public override string EditorTypeName
        {
            get { return RepositoryItemMyEdit.EditorName; }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public new RepositoryItemMyEdit Properties
        {
            get { return base.Properties as RepositoryItemMyEdit; }
        }

        //protected override void OnClickButton(DevExpress.XtraEditors.Drawing.EditorButtonObjectInfoArgs buttonInfo)
        //{
        //    ShowPopupForm();
        //    base.OnClickButton(buttonInfo);
        //}
        //protected virtual void ShowPopupForm()
        //{
        //    using (Form form = new Form())
        //    {
        //        form.StartPosition = FormStartPosition.Manual;
        //        form.Location = this.PointToScreen(new Point(0, Height));
        //        form.ShowDialog();
        //    }
        //}
    }
}

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved