DevExpress,GridControl如何添加自定义列,重写RepositoryItem

DevExpress,GridControl如何添加自定义列,重写RepositoryItem

如何向XtraGrid添加自定义控件

怎样向XtraGrid中添加自己创建的XtraEditors编辑控件

可以创建 RepositoryItem派生类,并且其声明静态构造方法和注册方法,如果要在设计器中使用还得给注册方法添加UserRepositoryItemAttribute属性标记,还必须重写RepositoryItemBaseEdit派生类的EditorTypeName属性

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

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

[C#例子]

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();
        //    }
        //}
    }
}


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值