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