DevExpress,GridControl如何添加自定义列,重写RepositoryItem
如何向XtraGrid添加自定义控件
怎样向XtraGrid中添加自己创建的XtraEditors编辑控件
可以创建 RepositoryItem派生类,并且为其声明静态构造方法和注册方法,如果要在设计器中使用还得给注册方法添加UserRepositoryItemAttribute属性标记,还必须重写RepositoryItem和BaseEdit派生类的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();
// }
//}
}
}